diff options
| author | Carl Meyer <carl@oddbird.net> | 2015-06-01 17:22:10 -0600 |
|---|---|---|
| committer | Carl Meyer <carl@oddbird.net> | 2015-06-02 12:07:54 -0600 |
| commit | 84522c0d165076d01cd034d7c381b75044daec8d (patch) | |
| tree | 8d0526b535f25f63cabb5dcbf8058dcc93145ec3 /django | |
| parent | 262d4db8c4c849b0fdd84550fb96472446cf90df (diff) | |
Fixed #24895 -- Fixed loading a pair of squashed migrations with a dependency.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/migrations/loader.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py index 24c1dc1d18..b2ba335ade 100644 --- a/django/db/migrations/loader.py +++ b/django/db/migrations/loader.py @@ -224,15 +224,29 @@ class MigrationLoader(object): for child_key in reverse_dependencies.get(replaced, set()): if child_key in migration.replaces: continue - # child_key may appear in a replacement + # List of migrations whose dependency on `replaced` needs + # to be updated to a dependency on `key`. + to_update = [] + # Child key may itself be replaced, in which case it might + # not be in `normal` anymore (depending on whether we've + # processed its replacement yet). If it's present, we go + # ahead and update it; it may be deleted later on if it is + # replaced, but there's no harm in updating it regardless. + if child_key in normal: + to_update.append(normal[child_key]) + # If the child key is replaced, we update its replacement's + # dependencies too, if necessary. (We don't know if this + # replacement will actually take effect or not, but either + # way it's OK to update the replacing migration). if child_key in reverse_replacements: - for replaced_child_key in reverse_replacements[child_key]: - if replaced in replacing[replaced_child_key].dependencies: - replacing[replaced_child_key].dependencies.remove(replaced) - replacing[replaced_child_key].dependencies.append(key) - else: - normal[child_key].dependencies.remove(replaced) - normal[child_key].dependencies.append(key) + for replaces_child_key in reverse_replacements[child_key]: + if replaced in replacing[replaces_child_key].dependencies: + to_update.append(replacing[replaces_child_key]) + # Actually perform the dependency update on all migrations + # that require it. + for migration_needing_update in to_update: + migration_needing_update.dependencies.remove(replaced) + migration_needing_update.dependencies.append(key) normal[key] = migration # Mark the replacement as applied if all its replaced ones are if all(applied_statuses): |
