﻿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
22325	Defining a custom user model in an app and having relations between it and other models in the app causes circular dependencies	Stephen Burrows	nobody	"I *think* the issue is that swappable_dependency resolves to app_label.__first__, which doesn't make a lot of sense when the app with the migrations is itself being migrated. Removing that line seems to temporarily resolve the issue, but if my app were ever used with a *different* AUTH_USER_MODEL, it would then presumably break again. (Also, I still get a circular dependency in the next migration that defines a relation to AUTH_USER_MODEL.)

Here are the important bits from *one* migration:

{{{
class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('app_label', '0002_blah_blah'),
    ]

    operations = [
        migrations.CreateModel(
            # This is the AUTH_USER_MODEL
            name='Person',
            fields=[
                ...
            ],
            options={
                u'verbose_name': u'person',
                u'verbose_name_plural': u'people',
            },
            bases=(models.Model,),
        ),
        migrations.CreateModel(
            name='PersonDiscount',
            fields=[
                ...
                ('person', models.ForeignKey(to=settings.AUTH_USER_MODEL, to_field=u'id')),
            ],
            options={
            },
            bases=(models.Model,),
        ),
    ]
}}}

Traceback:

{{{
Traceback (most recent call last):
  File ""./manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "".../django/django/core/management/__init__.py"", line 427, in execute_from_command_line
    utility.execute()
  File "".../django/django/core/management/__init__.py"", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "".../django/django/core/management/base.py"", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "".../django/django/core/management/base.py"", line 337, in execute
    output = self.handle(*args, **options)
  File "".../django/django/core/management/commands/migrate.py"", line 103, in handle
    plan = executor.migration_plan(targets)
  File "".../django/django/db/migrations/executor.py"", line 46, in migration_plan
    for migration in self.loader.graph.forwards_plan(target):
  File "".../django/django/db/migrations/graph.py"", line 53, in forwards_plan
    return self.dfs(node, lambda x: self.dependencies.get(x, set()))
  File "".../django/django/db/migrations/graph.py"", line 119, in dfs
    return _dfs(start, get_children, [])
  File "".../django/django/db/migrations/graph.py"", line 111, in _dfs
    results = _dfs(n, get_children, path) + results
  File "".../django/django/db/migrations/graph.py"", line 111, in _dfs
    results = _dfs(n, get_children, path) + results
  File "".../django/django/db/migrations/graph.py"", line 111, in _dfs
    results = _dfs(n, get_children, path) + results
  File "".../django/django/db/migrations/graph.py"", line 103, in _dfs
    raise CircularDependencyError(path[path.index(start):] + [start])
django.db.migrations.graph.CircularDependencyError: [('brambling', '0003_blah_blah'), ('brambling', '0003_blah_blah')]
}}}"	Bug	closed	Migrations	1.7-beta-1	Release blocker	fixed		Stephen Burrows ondrowan@… Jonas von Poser chtimbo@…	Accepted	1	0	0	1	0	0
