Opened 9 months ago

Closed 9 months ago

Last modified 9 months ago

#23322 closed Bug (fixed)

CircularDependencyError in migrations

Reported by: gabejackson Owned by: Markush2010
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 (8)

comment:1 Changed 9 months ago by gabejackson

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 9 months ago by gabejackson (previous) (diff)

comment:2 Changed 9 months ago by Markush2010

  • Owner changed from nobody to Markush2010
  • Status changed from new to assigned

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

comment:3 Changed 9 months ago by bmispelon

  • Triage Stage changed from Unreviewed to Accepted

Accepting per previous comment.

comment:4 Changed 9 months ago by Markush2010

  • Has patch set
  • Needs tests set

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

comment:5 Changed 9 months ago by andrewgodwin

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 Changed 9 months ago by Markush2010

  • Needs tests unset

Tests are there.

comment:7 Changed 9 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 144cff3f516f7c718cbe4bd3165e18781c09042a:

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

comment:8 Changed 9 months ago by Tim Graham <timograham@…>

In 2da20379c0dd0171eb11c188909096f708dd6095:

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

Backport of 144cff3f51 from master

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