[Django] #35463: Squash migrations inheriting dependencies from unsquashed migrations.

6 views
Skip to first unread message

Django

unread,
May 17, 2024, 8:21:05 AM5/17/24
to django-...@googlegroups.com
#35463: Squash migrations inheriting dependencies from unsquashed migrations.
------------------------------------------+------------------------
Reporter: Gordon Wrigley | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 4.2
Severity: Normal | Keywords: squash
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
We have a large system with several apps and a lot of interdependent
migrations. Currently 17 apps and a total of 1,266 migrations.
Squashing this is very difficult. One of the things that makes it much
more difficult is the change associated with
https://code.djangoproject.com/ticket/25945 where by dependencies are
copied between squashed and unsquashed migrations.
This means that while the unsquashed migrations still exist in the
codebase the squash that replaces them is dependent on all of the things
the individual migrations are dependent on.
With large squashes on different apps that refer to each other this
frequently creates circular dependencies between squashes where they don't
actually exist.
The net effect of this is I have squashes where I know the squashes don't
depend on each other and the dependencies listed in the squashes are
chosen to not lead to them depending on each other, however they end up
depending on each other because they inherit the dependencies of the
migrations they replace.
We are addressing this by reverting part of that change so it no longer
copy dependencies onto the squash, trusting that the squash knows what
it's dependencies should be.
{{{#!python
def patch_squash_migration_dependencies():
from django.db.migrations.graph import MigrationGraph

patchy.patch(
MigrationGraph.remove_replaced_nodes,
r"""\
@@ -28,7 +28,3 @@
child.add_parent(replacement_node)
for parent in replaced_node.parents:
parent.children.remove(replaced_node)
- # Again, to avoid self-referencing.
- if parent.key not in replaced:
- replacement_node.add_parent(parent)
- parent.add_child(replacement_node)
""",
)

}}}
As an aside, generally cross app dependencies are from foreign keys. When
you add a foreign key to another app you need to depend on the migrations
in that app. Django depends on the most recent migration by default. But
AFAIK it only really needs to depend on the last migration where the PK of
the target table changed (usually when the table was added). It's probably
a lot of work but I suspect that having the migration system figure that
out would reduce a lot of circular dependency issues.
--
Ticket URL: <https://code.djangoproject.com/ticket/35463>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 21, 2024, 6:37:28 AM5/21/24
to django-...@googlegroups.com
#35463: Squash migrations inheriting dependencies from unsquashed migrations.
--------------------------------+--------------------------------------
Reporter: Gordon Wrigley | Owner: nobody
Type: Uncategorized | Status: closed
Component: Migrations | Version: 4.2
Severity: Normal | Resolution: duplicate
Keywords: squash | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Sarah Boyce):

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

Comment:

Duplicate of #23337
--
Ticket URL: <https://code.djangoproject.com/ticket/35463#comment:1>
Reply all
Reply to author
Forward
0 new messages