summaryrefslogtreecommitdiff
path: root/tests/many_to_many
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2019-11-21 20:02:57 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-11-22 09:08:10 +0100
commit379bf1a2d41494360d86bc3cf8adc482abca5d63 (patch)
treed5fc5003b27c7dd365b4ae7a9405d07910184d16 /tests/many_to_many
parent8cc711999ab839c1a93cb228b35beac4a454fafc (diff)
downloaddjango-379bf1a2d41494360d86bc3cf8adc482abca5d63.tar.gz
Fixed #8467 -- Prevented crash when adding existent m2m relation with an invalid type.
This was an issue anymore on backends that allows conflicts to be ignored (Refs #19544) as long the provided values were coercible to the expected type. However on the remaining backends that don't support this feature, namely Oracle, this could still result in an IntegrityError. By attempting to coerce the provided values to the expected types in Python beforehand we allow the existing value set intersection in ManyRelatedManager._get_missing_target_ids to prevent the problematic insertion attempts. Thanks Baptiste Mispelon for triaging this old ticket against the current state of the master branch.
Diffstat (limited to 'tests/many_to_many')
-rw-r--r--tests/many_to_many/tests.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py
index a60ea42430..79d0fa420c 100644
--- a/tests/many_to_many/tests.py
+++ b/tests/many_to_many/tests.py
@@ -1,7 +1,7 @@
from unittest import mock
from django.db import transaction
-from django.test import TestCase, skipUnlessDBFeature
+from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from .models import (
Article, InheritedArticleA, InheritedArticleB, Publication, User,
@@ -158,6 +158,14 @@ class ManyToManyTests(TestCase):
with self.assertNumQueries(1):
self.a1.publications.add(self.p1, self.p2)
+ @skipIfDBFeature('supports_ignore_conflicts')
+ def test_add_existing_different_type(self):
+ # A single SELECT query is necessary to compare existing values to the
+ # provided one; no INSERT should be attempted.
+ with self.assertNumQueries(1):
+ self.a1.publications.add(str(self.p1.pk))
+ self.assertEqual(self.a1.publications.get(), self.p1)
+
@skipUnlessDBFeature('supports_ignore_conflicts')
def test_slow_add_ignore_conflicts(self):
manager_cls = self.a1.publications.__class__