#34623: Swappable dependencies always depend on first migration of app
------------------------------------------------+------------------------
Reporter: Shai Berger | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
This is a spin-off from https://github.com/django/django/pull/16861 and
#23528.
When a migration specifies a swappable dependency, it is given as
{{{"app_label.Model"}}}. But at run-time that gets translated into
{{{"app_label.__first__"}}}, and the model name is ignored. This works as
long as the model is defined by the time the dependent migration is run,
but if the model is not created in the first migration of its app, then
the right order of execution is no longer guaranteed.
This problem, if it manifests, is not at the level of either of the apps,
but only the project.
The ideal solution is that a swappable dependency will actually mean
"migrate that other app until the model shows up". That seems incompatible
with making a migration plan in advance.
Another solution may be to load the app's migrations and look for a
suitable `CreateModel` operation. That is not ideal, because models can be
created by other operations (obviously the built-in `RenameModel`, but
even an `AddField` with a M2M, not to mention 3rd-party operations).
A different approach would be just to check -- when a swappable dependency
is in place, after running the initial migration of the dependency app,
verify that the requested model exists, and if it doesn't, error out. That
may later be extended, by allowing a specific migration to marked
(explicitly, in its code) as providing a specific model, but that
extension may well be a YAGNI.
--
Ticket URL: <https://code.djangoproject.com/ticket/34623>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701887bbf5a66-cc0a13c6-f57f-4846-882c-a1f763d324a9-000000%40eu-central-1.amazonses.com.