Opened 8 hours ago

Last modified 7 hours ago

#36652 new Bug

Django Squashed Migrations Randmonly Passing/Failing Based On Set Iteration Order

Reported by: Jayden Kneller Owned by:
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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

Change History (2)

comment:1 by Jayden Kneller, 8 hours ago

If anyone needs help understanding the documentation about the management command, or the files that it creates, feel free to ask.

comment:2 by Jayden Kneller, 7 hours ago

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.

Note: See TracTickets for help on using tickets.
Back to Top