From b6e2b83901d841cf4d2179f650d1e7dca7e90c16 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Fri, 15 Sep 2023 04:04:50 +1000 Subject: [PATCH] Fixed #34841 -- Avoided rendering apps on state still requiring mutation. --- django/db/migrations/executor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/django/db/migrations/executor.py b/django/db/migrations/executor.py index eb738cf457..13afa5988f 100644 --- a/django/db/migrations/executor.py +++ b/django/db/migrations/executor.py @@ -224,6 +224,9 @@ class MigrationExecutor: # remaining applied migrations. last_unapplied_migration = plan[-1][0] state = states[last_unapplied_migration] + # Avoid mutating state with apps rendered as it's an expensive + # operation. + del state.apps for index, (migration, _) in enumerate(full_plan): if migration == last_unapplied_migration: for migration, _ in full_plan[index:]: