summaryrefslogtreecommitdiff
path: root/tests/migrations/test_executor.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/migrations/test_executor.py')
-rw-r--r--tests/migrations/test_executor.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py
index 8cab8732c4..e61d8f1276 100644
--- a/tests/migrations/test_executor.py
+++ b/tests/migrations/test_executor.py
@@ -684,6 +684,33 @@ class ExecutorTests(MigrationTestBase):
)
self.assertTableNotExists('record_migration_model')
+ def test_migrations_not_applied_on_deferred_sql_failure(self):
+ """Migrations are not recorded if deferred SQL application fails."""
+ class DeferredSQL:
+ def __str__(self):
+ raise DatabaseError('Failed to apply deferred SQL')
+
+ class Migration(migrations.Migration):
+ atomic = False
+
+ def apply(self, project_state, schema_editor, collect_sql=False):
+ schema_editor.deferred_sql.append(DeferredSQL())
+
+ executor = MigrationExecutor(connection)
+ with self.assertRaisesMessage(DatabaseError, 'Failed to apply deferred SQL'):
+ executor.apply_migration(
+ ProjectState(),
+ Migration('0001_initial', 'deferred_sql'),
+ )
+ # The migration isn't recorded as applied since it failed.
+ migration_recorder = MigrationRecorder(connection)
+ self.assertIs(
+ migration_recorder.migration_qs.filter(
+ app='deferred_sql', name='0001_initial',
+ ).exists(),
+ False,
+ )
+
class FakeLoader:
def __init__(self, graph, applied):