Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #29897 -- Adjusted auto-detector swappable MTI dependency resolution. #10577

Merged
merged 1 commit into from Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions django/db/migrations/autodetector.py
Expand Up @@ -345,6 +345,9 @@ def _sort_migrations(self):
dependency_graph = {op: set() for op in ops}
for op in ops:
for dep in op._auto_deps:
# Resolve intra-app dependencies to handle circular
# references involving a swappable model.
dep = self._resolve_dependency(dep)[0]
if dep[0] == app_label:
for op2 in ops:
if self.check_dependency(op2, dep):
Expand Down
12 changes: 12 additions & 0 deletions tests/migrations/test_autodetector.py
Expand Up @@ -2348,6 +2348,18 @@ def test_circular_dependency_swappable_self(self):
self.assertOperationTypes(changes, 'a', 0, ["CreateModel"])
self.assertMigrationDependencies(changes, 'a', 0, [])

@override_settings(AUTH_USER_MODEL='a.User')
def test_swappable_circular_multi_mti(self):
with isolate_lru_cache(apps.get_swappable_settings_name):
parent = ModelState('a', 'Parent', [
('user', models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE))
])
child = ModelState('a', 'Child', [], bases=('a.Parent',))
user = ModelState('a', 'User', [], bases=(AbstractBaseUser, 'a.Child'))
changes = self.get_changes([], [parent, child, user])
self.assertNumberMigrations(changes, 'a', 1)
self.assertOperationTypes(changes, 'a', 0, ['CreateModel', 'CreateModel', 'CreateModel', 'AddField'])

@mock.patch('django.db.migrations.questioner.MigrationQuestioner.ask_not_null_addition',
side_effect=AssertionError("Should not have prompted for not null addition"))
def test_add_blank_textfield_and_charfield(self, mocked_ask_method):
Expand Down