Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23315 closed Bug (fixed)

Cannot resolve operation dependencies

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

Description

The auto detector cannot create migrations for the project located at: https://github.com/gabejackson/django-migration-test
Using Django==1.7c2 and python 2.7.5
The command used is:

./manage.py makemigrations --dry-run

which leads to:

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/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/gabejackson/venv/django-1.7/lib/python2.7/site-packages/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/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/gabejackson/venv/django-1.7/lib/python2.7/site-packages/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/Users/gabejackson/venv/django-1.7/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 111, in handle
    convert_apps=app_labels or None,
  File "/Users/gabejackson/venv/django-1.7/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 50, in changes
    changes = self._detect_changes(convert_apps, graph)
  File "/Users/gabejackson/venv/django-1.7/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 288, in _detect_changes
    raise ValueError("Cannot resolve operation dependencies")
ValueError: Cannot resolve operation dependencies

Change History (12)

comment:1 by Gabe Jackson, 10 years ago

I further reduced the model to only 2 apps and 4 models. I found out that the auto-detector is non-deterministic depending on the alphabetical names of the models.
If you run the project with the class APackage it will fail with "Cannot resolve operation deps". If you rename APackage to DPackage (DPackage is alphabetically now later than DeliveryCountry) and run makemigrations --dry-run again, it works...

Apparently there is some issue with sorting classes alphabetically. Hope this helps..

comment:2 by Collin Anderson, 10 years ago

Cc: cmawebsite@… added
Triage Stage: UnreviewedAccepted

I get the same error with these simple models on the latest code. It's a circular dependency of ForeignKeys between apps, and I don't see anything saying that this isn't supported.

comment:3 by Collin Anderson, 10 years ago

I've reproduced the project from scratch just to be sure. Here are the simple models: https://github.com/collinanderson/ticket23315/commit/c813d1b7e8b46f86d0fb01e7d19bb69e80c8b76a

Last edited 10 years ago by Collin Anderson (previous) (diff)

comment:4 by Andrew Godwin <andrew@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 9247da1032c1b8c98b0fcfb278bbbdbc8edc8783:

Fixed #23315: Operational dependency fail with mixed create/add

comment:5 by Andrew Godwin <andrew@…>, 10 years ago

In 824e02bf836affa182dd4bcb7b3e1796f1389b38:

[1.7.x] Fixed #23315: Operational dependency fail with mixed create/add

comment:6 by Tim Graham, 10 years ago

Resolution: fixed
Status: closednew

The new test fails on Python 3.4:

======================================================================
ERROR [0.001s]: test_circular_dependency_mixed_addcreate (migrations.test_autodetector.AutodetectorTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jenkins/workspace/django-master/database/sqlite3/python/python3.4/tests/migrations/test_autodetector.py", line 1099, in test_circular_dependency_mixed_addcreate
    changes = autodetector._detect_changes()
  File "/home/jenkins/workspace/django-master/database/sqlite3/python/python3.4/django/db/migrations/autodetector.py", line 172, in _detect_changes
    self.generate_created_models()
  File "/home/jenkins/workspace/django-master/database/sqlite3/python/python3.4/django/db/migrations/autodetector.py", line 497, in generate_created_models
    dep_app_label = field.rel.to._meta.app_label
AttributeError: 'str' object has no attribute '_meta'

The string is "a.person" (but resolves to <class 'Person'> when the test passes).

comment:7 by Tim Graham, 10 years ago

Owner: changed from nobody to Tim Graham
Status: newassigned

I'm looking into this. It seems to be a non-deterministic issue, perhaps ordering related.

comment:8 by Andrew Godwin, 10 years ago

That's odd, because all the other relationships in that test file are fine under 3.4. It's likely an issue in the State's reconstruction of it. Happy to look at this instead if you want to hand it over.

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

In d1299fce0eeeb2a7749fecafc87260462e75aac9:

Fixed migrations tests added in refs #23315.

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

In 6981eced83ea2d6462b21c12ecea044e02e56d05:

[1.7.x] Fixed migrations tests added in refs #23315.

Backport of d1299fce0e from master

comment:11 by Tim Graham, 10 years ago

Resolution: fixed
Status: assignedclosed

do_pending_lookups wasn't resolving the field due to a case mismatch.

comment:12 by Andrew Godwin <andrew@…>, 10 years ago

In 9247da1032c1b8c98b0fcfb278bbbdbc8edc8783:

Fixed #23315: Operational dependency fail with mixed create/add

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