diff options
| author | Tommy Beadle <tbeadle@arbor.net> | 2015-04-14 10:43:57 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-24 08:59:20 -0400 |
| commit | d3fdaf907db6a5be4d0391532d7e65688c19e851 (patch) | |
| tree | f29086e0f08340e6eed939c8f55ac97475f4aac1 /django | |
| parent | 45ed19de687d324d3ba852eea93b1afa575e482f (diff) | |
Fixed #23727 -- Inhibited the post_migrate signal when using serialized_rollback.
When using a TransactionTestCase with serialized_rollback=True,
after creating the database and running its migrations (along with
emitting the post_migrate signal), the contents of the database
are serialized to _test_serialized_contents.
After the first test case, _fixture_teardown() would flush the
tables but then the post_migrate signal would be emitted and new
rows (with new PKs) would be created in the django_content_type
table. Then in any subsequent test cases in a suite,
_fixture_setup() attempts to deserialize the content of
_test_serialized_contents, but these rows are identical to the
rows already in the database except for their PKs. This causes an
IntegrityError due to the unique constraint in the
django_content_type table.
This change made it so that in the above scenario the post_migrate
signal is not emitted after flushing the tables, since it will be
repopulated during fixture_setup().
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/testcases.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py index 93ad8b9354..c4ee8984a9 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -940,10 +940,19 @@ class TransactionTestCase(SimpleTestCase): # when flushing only a subset of the apps for db_name in self._databases_names(include_mirrors=False): # Flush the database + inhibit_post_migrate = ( + self.available_apps is not None + or ( + # Inhibit the post_migrate signal when using serialized + # rollback to avoid trying to recreate the serialized data. + self.serialized_rollback and + hasattr(connections[db_name], '_test_serialized_contents') + ) + ) call_command('flush', verbosity=0, interactive=False, database=db_name, reset_sequences=False, allow_cascade=self.available_apps is not None, - inhibit_post_migrate=self.available_apps is not None) + inhibit_post_migrate=inhibit_post_migrate) def assertQuerysetEqual(self, qs, values, transform=repr, ordered=True, msg=None): items = six.moves.map(transform, qs) |
