﻿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
30029	Generate migration dependencies in a deterministic order	Dakota Hawkins	Dakota Hawkins	"From [https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/django-users/GUBw8lp1U24/mMyIBeiSAgAJ this google groups discussion]:

> We haven't really deployed yet, so generally to make migrations we're deleting existing migration files and re-running makemigrations.
>
> We have two apps, and one of them depends on the other as well as django.contrib.auth. In that app's migrations the dependencies often swap order seemingly indeterminately.
>
> [[Image(https://i.imgur.com/nJxyuXT.png)]]
>
> The resulting migration includes either:
>
> {{{
> class Migration(migrations.Migration):
>     initial = True
>     dependencies = [
>         ('auth', '0009_alter_user_last_name_max_length'),
>         ('app2', '0001_initial'),
>     ]
>     ...
> }}}
>
> or:
> 
> {{{
> class Migration(migrations.Migration):
>     initial = True
>     dependencies = [
>         ('app2', '0001_initial'),
>         ('auth', '0009_alter_user_last_name_max_length'),
>     ]
>     ...
> }}}
> 
> and it seems to switch back and forth with nearly every run.
> 
> Does anybody know why, or how to nail down the order? It doesn't seem to make a technical difference, but I'd like to avoid the churn/noise in our repo.

According to Simon Charette in that discussion:
> It should be a simple matter of using sorted in MigrationWriter.as_string[0].

I poked around the code a bit, in hopes of first writing a failing unit test and then fixing the issue, but I'm not sure how to write the test with multiple interdependent apps since `temporary_migration_module` seems to support only a single app. Another concern is that the test may be flaky since the current order is indeterminate... it may take some arbitrary number of iterations to be reasonably certain the case could have been reproduced by one of them.

I'd be happy to investigate further if somebody could help me get started with some advice on writing that test.
"	Cleanup/optimization	closed	Core (Management commands)	dev	Normal	duplicate	migrations, makemigrations		Unreviewed	1	0	0	0	0	0
