﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36652	Loading squashed migrations from disk raises CircularDependencyError indeterministically	Jayden Kneller	Augusto Pontes	"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"	Bug	closed	Migrations	dev	Normal	fixed	squashed		Ready for checkin	1	0	0	0	0	0
