diff options
author | Simon Charette <charette.s@gmail.com> | 2019-02-15 01:01:25 -0500 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2019-02-21 10:20:47 -0500 |
commit | 28712d8acfffa9cdabb88cb610bae14913fa185d (patch) | |
tree | c2237f1578ddf7a1c3a6d975a5a972d0ed59a295 /tests/many_to_many | |
parent | dd32f9a3a21272e784d434a6f9ca9f07aeedb50a (diff) | |
download | django-28712d8acfffa9cdabb88cb610bae14913fa185d.tar.gz |
Refs #19544 -- Ignored auto-created through additions conflicts if supported.
This prevents IntegrityError caused by race conditions between missing ids
retrieval and bulk insertions.
Diffstat (limited to 'tests/many_to_many')
-rw-r--r-- | tests/many_to_many/tests.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py index 933eb23a7a..adde2ac563 100644 --- a/tests/many_to_many/tests.py +++ b/tests/many_to_many/tests.py @@ -117,6 +117,16 @@ class ManyToManyTests(TestCase): ] ) + @skipUnlessDBFeature('supports_ignore_conflicts') + def test_add_ignore_conflicts(self): + manager_cls = self.a1.publications.__class__ + # Simulate a race condition between the missing ids retrieval and + # the bulk insertion attempt. + missing_target_ids = {self.p1.id} + with mock.patch.object(manager_cls, '_get_missing_target_ids', return_value=missing_target_ids) as mocked: + self.a1.publications.add(self.p1) + mocked.assert_called_once() + def test_related_sets(self): # Article objects have access to their related Publication objects. self.assertQuerysetEqual(self.a1.publications.all(), ['<Publication: The Python Journal>']) |