[Django] #36652: Django Squashed Migrations Randmonly Passing/Failing Based On Set Iteration Order

5 views
Skip to first unread message

Django

unread,
Oct 9, 2025, 4:13:42 PM10/9/25
to django-...@googlegroups.com
#36652: Django Squashed Migrations Randmonly Passing/Failing Based On Set Iteration
Order
--------------------------------+--------------------------------------
Reporter: Jayden Kneller | Type: Bug
Status: new | Component: Migrations
Version: dev | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
This could be a duplicate of many other projects, but I've figured out a
bug fix that may also solve the issues of the other projects.

I've created a github repo that contains a project with migrations,
squashed migrations, and a management command. If someone checks out the
repo and runs the `showmigrations` management command multiple times, the
results will pass or fail in a way that appears random.

https://github.com/arrai-innovations/django-migrationnames

I've tracked the issue down to the order that a set is iterated over. If
that set is turned into a list, without any other code changes, the issue
shown in this test project stops failing and instead passes 100% of the
time. I can't guarrantee it will fix every other users issues with
circular dependency errors, but it will stop the randomness that is
happening because of iterating through a set.

If someone uses the management command I created, called `show_issue`, it
will create output with a number of files that contain results parsed from
the patched `MigrationLoader`. The data comes from
`loader.graph.node_map`, where the migrations and their children are
stored. In essence, there are 8 different possibilities that the
migrations and children can be figured out as, because of the set. 2 of
these 8 possibilities pass and the other 6 cause circular dependency
errors. The fix changes things to have 1 possibility for the way
migrations and children are figured out, and it passes.

The randomness of iterating over the set and having 8 possible
migration/children setups is what makes things difficult to deal with when
working with squashed migrations.

I've written about the management command and how to use it in the
README.md of the django-migrationnames project.

The fix is really small, which I have in a fork. Since it is very small,
this is the change:

https://github.com/jayden-
arrai/django/commit/fceaa5820edfbd7128082e7d199034963ae6cd33
--
Ticket URL: <https://code.djangoproject.com/ticket/36652>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 9, 2025, 4:14:55 PM10/9/25
to django-...@googlegroups.com
#36652: Django Squashed Migrations Randmonly Passing/Failing Based On Set Iteration
Order
--------------------------------+--------------------------------------
Reporter: Jayden Kneller | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Comment (by Jayden Kneller):

If anyone needs help understanding the documentation about the management
command, or the files that it creates, feel free to ask.
--
Ticket URL: <https://code.djangoproject.com/ticket/36652#comment:1>

Django

unread,
Oct 9, 2025, 4:25:18 PM10/9/25
to django-...@googlegroups.com
#36652: Django Squashed Migrations Randmonly Passing/Failing Based On Set Iteration
Order
--------------------------------+--------------------------------------
Reporter: Jayden Kneller | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Comment (by Jayden Kneller):

I don't know if this needs tests, or how anyone would make a test for it.
Unless the project migrations I have can somehow be converted into a test.
The randomness of it makes it difficult.
--
Ticket URL: <https://code.djangoproject.com/ticket/36652#comment:2>

Django

unread,
Oct 10, 2025, 4:22:37 PM10/10/25
to django-...@googlegroups.com
#36652: Django Squashed Migrations Randmonly Passing/Failing Based On Set Iteration
Order
--------------------------------+--------------------------------------
Reporter: Jayden Kneller | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Comment (by Augusto Pontes):

Hi jayden, your repo seems to be a great idea to solve this problem of the
migrations, im still reading your readme, and definetely this will need
automated tests, also documentation
--
Ticket URL: <https://code.djangoproject.com/ticket/36652#comment:3>

Django

unread,
Oct 10, 2025, 4:44:16 PM10/10/25
to django-...@googlegroups.com
#36652: Django Squashed Migrations Randmonly Passing/Failing Based On Set Iteration
Order
--------------------------------+--------------------------------------
Reporter: Jayden Kneller | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Comment (by Jayden Kneller):

I should also mention that if the old migrations are removed, so that only
the squashed migrations exist, then it doesn't matter if the migration
names are a set or list. The issue where this is a problem seems to only
be at the point where both old migrations and the squashed migrations
exist. Basically when you are about to deploy the squashed migrations for
the first time and deploy it to a site so it adds them into the
db_migrations table.
--
Ticket URL: <https://code.djangoproject.com/ticket/36652#comment:4>

Django

unread,
Oct 10, 2025, 5:34:26 PM10/10/25
to django-...@googlegroups.com
#36652: Django Squashed Migrations Randmonly Passing/Failing Based On Set Iteration
Order
--------------------------------+--------------------------------------
Reporter: Jayden Kneller | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Comment (by Jayden Kneller):

If it is possible to use this repo in the creation of the automated tests,
then please do. It was a lot of work to rename everything to obscure the
original project. I renamed all the migration names in the process as
well, because of some of their names. I'm glad the operations in the old
migrations don't need to exist in order to have this issue occur, that
removed a lot of code. I'm not sure if it would be possible to trim down
the number of apps and migrations and still have a situation like this
occur. At the very least, I think I got the code that exists down to
about the smallest amount that I could.

But, I'm not sure how you would make an automated test for this. What
would need to be tested? Because the set seems to iterate in the same
order within the running process no matter how many times you iterate over
it, and doesn't always fail. That must make things more difficult to test.
I was forced to add the shuffle in the patched MigrationLoader due to the
same process iteration issue, which I wasn't expecting.
--
Ticket URL: <https://code.djangoproject.com/ticket/36652#comment:5>
Reply all
Reply to author
Forward
0 new messages