Opened 10 years ago

Closed 10 years ago

Last modified 5 years ago

#23322 closed Bug (fixed)

CircularDependencyError in migrations

Reported by: Gabe Jackson Owned by: Markus Holtermann
Component: Migrations Version: 1.7-rc-2
Severity: Release blocker Keywords: migrations, circular dependency
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django.db.migrations.graph.CircularDependencyError

Test Project is located here: https://github.com/gabejackson/django-migration-test/tree/circ_dep_1

Steps to reproduce:
Install stable/1.7.x branch in venv
./manage.py makemigrations
... [OK]
./manage.py migrate

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/gabejackson/venv/django-1.7/src/django/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/gabejackson/venv/django-1.7/src/django/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/gabejackson/venv/django-1.7/src/django/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/gabejackson/venv/django-1.7/src/django/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/Users/gabejackson/venv/django-1.7/src/django/django/core/management/commands/migrate.py", line 106, in handle
    plan = executor.migration_plan(targets)
  File "/Users/gabejackson/venv/django-1.7/src/django/django/db/migrations/executor.py", line 49, in migration_plan
    for migration in self.loader.graph.forwards_plan(target):
  File "/Users/gabejackson/venv/django-1.7/src/django/django/db/migrations/graph.py", line 55, in forwards_plan
    return self.dfs(node, lambda x: self.dependencies.get(x, set()))
  File "/Users/gabejackson/venv/django-1.7/src/django/django/db/migrations/graph.py", line 121, in dfs
    return _dfs(start, get_children, [])
  File "/Users/gabejackson/venv/django-1.7/src/django/django/db/migrations/graph.py", line 113, in _dfs
    results = _dfs(n, get_children, path) + results
  File "/Users/gabejackson/venv/django-1.7/src/django/django/db/migrations/graph.py", line 113, in _dfs
    results = _dfs(n, get_children, path) + results
  File "/Users/gabejackson/venv/django-1.7/src/django/django/db/migrations/graph.py", line 113, in _dfs
    results = _dfs(n, get_children, path) + results
  File "/Users/gabejackson/venv/django-1.7/src/django/django/db/migrations/graph.py", line 113, in _dfs
    results = _dfs(n, get_children, path) + results
  File "/Users/gabejackson/venv/django-1.7/src/django/django/db/migrations/graph.py", line 105, in _dfs
    raise CircularDependencyError(path[path.index(start):] + [start])
django.db.migrations.graph.CircularDependencyError: [(u'a', u'0001_initial'), ('c', u'0001_initial'), (u'b', u'0001_initial'), (u'a', u'0001_initial')]

Change History (9)

comment:1 by Gabe Jackson, 10 years ago

Added a Graph of the Models if that helps anybody: https://github.com/gabejackson/django-migration-test/blob/circ_dep_1/models.pdf

CAUTION: Custom user model in effect.

Last edited 10 years ago by Gabe Jackson (previous) (diff)

comment:2 by Markus Holtermann, 10 years ago

Owner: changed from nobody to Markus Holtermann
Status: newassigned

I can confirm the bug. I'm working on a fix.

comment:3 by Baptiste Mispelon, 10 years ago

Triage Stage: UnreviewedAccepted

Accepting per previous comment.

comment:4 by Markus Holtermann, 10 years ago

Has patch: set
Needs tests: set

Here's the pull request. Needs some tests though: https://github.com/django/django/pull/3093

comment:5 by Andrew Godwin, 10 years ago

Without a small test case writing a test is going to be very hard. I can have a go if you're willing to assign the ticket to me.

comment:6 by Markus Holtermann, 10 years ago

Needs tests: unset

Tests are there.

comment:7 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 144cff3f516f7c718cbe4bd3165e18781c09042a:

Fixed #23322 -- Use resolved swappable model for dependency resolution during makemigrations

comment:8 by Tim Graham <timograham@…>, 10 years ago

In 2da20379c0dd0171eb11c188909096f708dd6095:

[1.7.x] Fixed #23322 -- Use resolved swappable model for dependency resolution during makemigrations

Backport of 144cff3f51 from master

comment:9 by Tim Graham <timograham@…>, 5 years ago

In f1855fd8:

Refs #23322 -- Removed unnecessary "and" clause in the autodetector.

If the depedency was swappable then it'll be resolved at this point.

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