summaryrefslogtreecommitdiff
path: root/tests/many_to_many
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2019-12-19 11:08:02 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-12-19 13:33:05 +0100
commita3fc24f01484d4bdd106bc6d7c49049fc5352af6 (patch)
tree19f529eeff3cee331cff528ed6bd9fe86a595edd /tests/many_to_many
parent5a4d7285bd10bd40d9f7e574a7c421eb21094858 (diff)
downloaddjango-a3fc24f01484d4bdd106bc6d7c49049fc5352af6.tar.gz
Fixed #31095 -- Made RelatedManager.set() preserve existing m2m relations with an invalid type.
Diffstat (limited to 'tests/many_to_many')
-rw-r--r--tests/many_to_many/tests.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py
index 79d0fa420c..b4314580ec 100644
--- a/tests/many_to_many/tests.py
+++ b/tests/many_to_many/tests.py
@@ -469,6 +469,19 @@ class ManyToManyTests(TestCase):
self.a4.publications.set([], clear=True)
self.assertQuerysetEqual(self.a4.publications.all(), [])
+ def test_set_existing_different_type(self):
+ # Existing many-to-many relations remain the same for values provided
+ # with a different type.
+ ids = set(Publication.article_set.through.objects.filter(
+ article__in=[self.a4, self.a3],
+ publication=self.p2,
+ ).values_list('id', flat=True))
+ self.p2.article_set.set([str(self.a4.pk), str(self.a3.pk)])
+ new_ids = set(Publication.article_set.through.objects.filter(
+ publication=self.p2,
+ ).values_list('id', flat=True))
+ self.assertEqual(ids, new_ids)
+
def test_assign_forward(self):
msg = (
"Direct assignment to the reverse side of a many-to-many set is "