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:10:04 -0600 |
| commit | 98b40ffe61260fca38230ad05d7f65a78e57ec66 (patch) | |
| tree | 126a15e231e47242a6d695a62dcd81ff1d007f9f /django | |
| parent | 7f92b6e576daace8051785dc046aca00bdccfed4 (diff) | |
[1.8.x] Fixed #24895 -- Fixed loading a pair of squashed migrations with a dependency.
Backport of 84522c0d165076d01cd034d7c381b75044daec8d from master.
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 fccf7d3205..b10b84f6f8 100644 --- a/django/db/migrations/loader.py +++ b/django/db/migrations/loader.py @@ -222,15 +222,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): |
