diff options
| author | Evan Grim <evan@mirgnave.com> | 2017-07-11 11:40:18 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-08-10 19:21:14 -0400 |
| commit | 7937cc16f5fafb33a53b9a9ff286229fcc5ba67f (patch) | |
| tree | 27f5226e663b8f69efea01ee54a533b9c0e7161e /tests | |
| parent | 5893eaddf4c866c2cd3f53660a3ffaf4d9db5dfa (diff) | |
Fixed #28386 -- Made operations within non-atomic migrations honor the operation's atomic flag when migrating backwards.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_executor.py | 8 | ||||
| -rw-r--r-- | tests/migrations/test_migrations_atomic_operation/0001_initial.py | 2 | ||||
| -rw-r--r-- | tests/migrations/test_operations.py | 2 |
3 files changed, 11 insertions, 1 deletions
diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py index d6cc802149..fdbc724faf 100644 --- a/tests/migrations/test_executor.py +++ b/tests/migrations/test_executor.py @@ -126,6 +126,14 @@ class ExecutorTests(MigrationTestBase): migrations_apps = executor.loader.project_state(("migrations", "0001_initial")).apps Editor = migrations_apps.get_model("migrations", "Editor") self.assertFalse(Editor.objects.exists()) + # Record previous migration as successful. + executor.migrate([("migrations", "0001_initial")], fake=True) + # Rebuild the graph to reflect the new DB state. + executor.loader.build_graph() + # Migrating backwards is also atomic. + with self.assertRaisesMessage(RuntimeError, "Abort migration"): + executor.migrate([("migrations", None)]) + self.assertFalse(Editor.objects.exists()) @override_settings(MIGRATION_MODULES={ "migrations": "migrations.test_migrations", diff --git a/tests/migrations/test_migrations_atomic_operation/0001_initial.py b/tests/migrations/test_migrations_atomic_operation/0001_initial.py index 415186423f..47ae3df5e9 100644 --- a/tests/migrations/test_migrations_atomic_operation/0001_initial.py +++ b/tests/migrations/test_migrations_atomic_operation/0001_initial.py @@ -18,5 +18,5 @@ class Migration(migrations.Migration): ("name", models.CharField(primary_key=True, max_length=255)), ], ), - migrations.RunPython(raise_error, atomic=True), + migrations.RunPython(raise_error, reverse_code=raise_error, atomic=True), ] diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 86dbb84411..13b511f3aa 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -2055,9 +2055,11 @@ class OperationTests(OperationTestBase): with self.assertRaises(ValueError): with connection.schema_editor() as editor: atomic_migration.unapply(project_state, editor) + self.assertEqual(project_state.apps.get_model("test_runpythonatomic", "Pony").objects.count(), 0) with self.assertRaises(ValueError): with connection.schema_editor() as editor: non_atomic_migration.unapply(project_state, editor) + self.assertEqual(project_state.apps.get_model("test_runpythonatomic", "Pony").objects.count(), 1) # Verify deconstruction. definition = non_atomic_migration.operations[0].deconstruct() self.assertEqual(definition[0], "RunPython") |
