Opened 2 years ago

Closed 2 years ago

Last modified 2 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 (8)

comment:1 Changed 2 years ago by Gabe Jackson

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 2 years ago by Gabe Jackson (previous) (diff)

comment:2 Changed 2 years ago by Markus Holtermann

Owner: changed from nobody to Markus Holtermann
Status: newassigned

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

comment:3 Changed 2 years ago by Baptiste Mispelon

Triage Stage: UnreviewedAccepted

Accepting per previous comment.

comment:4 Changed 2 years ago by Markus Holtermann

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 2 years ago by Andrew Godwin

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 2 years ago by Markus Holtermann

Needs tests: unset

Tests are there.

comment:7 Changed 2 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 144cff3f516f7c718cbe4bd3165e18781c09042a:

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

comment:8 Changed 2 years 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