-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #23727 -- Inhibited the post_migrate signal when using serializ…
…ed_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().
- Loading branch information
Showing
4 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
from django.test import TransactionTestCase, mock | |||
|
|||
|
|||
class TestSerializedRollbackInhibitsPostMigrate(TransactionTestCase): | |||
""" | |||
TransactionTestCase._fixture_teardown() inhibits the post_migrate signal | |||
for test classes with serialized_rollback=True. | |||
""" | |||
available_apps = ['test_utils'] | |||
serialized_rollback = True | |||
|
|||
def setUp(self): | |||
# self.available_apps must be None to test the serialized_rollback | |||
# condition. | |||
self.available_apps = None | |||
|
|||
def tearDown(self): | |||
self.available_apps = ['test_utils'] | |||
|
|||
@mock.patch('django.test.testcases.call_command') | |||
def test(self, call_command): | |||
# with a mocked call_command(), this doesn't have any effect. | |||
self._fixture_teardown() | |||
call_command.assert_called_with( | |||
'flush', interactive=False, allow_cascade=False, | |||
reset_sequences=False, inhibit_post_migrate=True, | |||
database='default', verbosity=0, | |||
) |