[Django] #34623: Swappable dependencies always depend on first migration of app

7 views
Skip to first unread message

Django

unread,
Jun 2, 2023, 6:55:21 AM6/2/23
to django-...@googlegroups.com
#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.

Django

unread,
Jun 2, 2023, 7:00:21 AM6/2/23
to django-...@googlegroups.com
#34623: Swappable dependencies always depend on first migration of app
-------------------------------------+-------------------------------------

Reporter: Shai Berger | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Migrations | Version: dev
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

It's probably a duplicate of #23694.

--
Ticket URL: <https://code.djangoproject.com/ticket/34623#comment:1>

Django

unread,
Jun 2, 2023, 7:15:15 AM6/2/23
to django-...@googlegroups.com
#34623: Swappable dependencies always depend on first migration of app
-------------------------------------+-------------------------------------
Reporter: Shai Berger | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Migrations | Version: dev
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Shai Berger):

Replying to [comment:1 Mariusz Felisiak]:


> It's probably a duplicate of #23694.

Yes, it is, but in the
[https://code.djangoproject.com/ticket/23694#comment:2 closing comment]
Andrew said "I'd love to know a way round it" and I believe I have
suggested one here.

--
Ticket URL: <https://code.djangoproject.com/ticket/34623#comment:2>

Django

unread,
Jun 2, 2023, 7:24:23 AM6/2/23
to django-...@googlegroups.com
#34623: Swappable dependencies always depend on first migration of app
-------------------------------------+-------------------------------------
Reporter: Shai Berger | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Migrations | Version: dev
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:2 Shai Berger]:


> Replying to [comment:1 Mariusz Felisiak]:
> > It's probably a duplicate of #23694.
>
> Yes, it is, but in the
[https://code.djangoproject.com/ticket/23694#comment:2 closing comment]
Andrew said "I'd love to know a way round it" and I believe I have
suggested one here.

Can you add a comment to the #23694? We should keep a discussion in the
single place.

--
Ticket URL: <https://code.djangoproject.com/ticket/34623#comment:3>

Reply all
Reply to author
Forward
0 new messages