(self, migration_key)
| 233 | return resolved_keys |
| 234 | |
| 235 | def replace_migration(self, migration_key): |
| 236 | if completed_replacement := self.replacements_progress.get(migration_key, None): |
| 237 | return |
| 238 | elif completed_replacement is False: |
| 239 | # Called before but not finished the replacement, this means there |
| 240 | # is a circular dependency. |
| 241 | raise CommandError( |
| 242 | f"Cyclical squash replacement found, starting at {migration_key}" |
| 243 | ) |
| 244 | self.replacements_progress[migration_key] = False |
| 245 | migration = self.replacements[migration_key] |
| 246 | # Process potential squashed migrations that the migration replaces. |
| 247 | for replace_migration_key in migration.replaces: |
| 248 | if replace_migration_key in self.replacements: |
| 249 | self.replace_migration(replace_migration_key) |
| 250 | |
| 251 | replaced_keys = self._resolve_replaced_migration_keys(migration) |
| 252 | # Get applied status of each found replacement target. |
| 253 | applied_statuses = [ |
| 254 | (target in self.applied_migrations) for target in replaced_keys |
| 255 | ] |
| 256 | # The replacing migration is only marked as applied if all of its |
| 257 | # replacement targets are applied. |
| 258 | if all(applied_statuses): |
| 259 | self.applied_migrations[migration_key] = migration |
| 260 | else: |
| 261 | self.applied_migrations.pop(migration_key, None) |
| 262 | # A replacing migration can be used if either all or none of its |
| 263 | # replacement targets have been applied. |
| 264 | if all(applied_statuses) or (not any(applied_statuses)): |
| 265 | self.graph.remove_replaced_nodes(migration_key, migration.replaces) |
| 266 | else: |
| 267 | # This replacing migration cannot be used because it is |
| 268 | # partially applied. Remove it from the graph and remap |
| 269 | # dependencies to it (#25945). |
| 270 | self.graph.remove_replacement_node(migration_key, migration.replaces) |
| 271 | |
| 272 | self.replacements_progress[migration_key] = True |
| 273 | |
| 274 | def build_graph(self): |
| 275 | """ |
no test coverage detected