Refs #26706, Refs #34633 -- Added test for prefetch_related() cache invalidation in ManyRelatedManager.create().

This commit is contained in:
Mariusz Felisiak 2023-06-06 07:33:59 +02:00 committed by GitHub
parent 51fdea6841
commit 40a2c811e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -512,6 +512,12 @@ class ManyToManyTests(TestCase):
a4.publications.add(self.p1)
self.assertEqual(a4.publications.count(), 2)
def test_create_after_prefetch(self):
a4 = Article.objects.prefetch_related("publications").get(id=self.a4.id)
self.assertSequenceEqual(a4.publications.all(), [self.p2])
p5 = a4.publications.create(title="Django beats")
self.assertCountEqual(a4.publications.all(), [self.p2, p5])
def test_set_after_prefetch(self):
a4 = Article.objects.prefetch_related("publications").get(id=self.a4.id)
self.assertEqual(a4.publications.count(), 1)