mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #31095 -- Made RelatedManager.set() preserve existing m2m relations with an invalid type.
This commit is contained in:
parent
5a4d7285bd
commit
a3fc24f014
2 changed files with 15 additions and 1 deletions
|
@ -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 "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue