1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[4.1.x] Fixed #33984 -- Reverted "Fixed #32980 -- Made models cache related managers."

This reverts 4f8c7fd9d9 and adds
two regression tests:
- test_related_manager_refresh(), and
- test_create_copy_with_m2m().

Thanks joeli for the report.
Backport of 5e0aa362d9 from main
This commit is contained in:
Mariusz Felisiak
2022-09-30 18:18:33 +02:00
parent ecf6506f44
commit 7a1675806a
12 changed files with 47 additions and 176 deletions

View File

@@ -92,6 +92,25 @@ class ManyToManyTests(TestCase):
a5.authors.remove(user_2.username)
self.assertSequenceEqual(a5.authors.all(), [])
def test_related_manager_refresh(self):
user_1 = User.objects.create(username="Jean")
user_2 = User.objects.create(username="Joe")
self.a3.authors.add(user_1.username)
self.assertSequenceEqual(user_1.article_set.all(), [self.a3])
# Change the username on a different instance of the same user.
user_1_from_db = User.objects.get(pk=user_1.pk)
self.assertSequenceEqual(user_1_from_db.article_set.all(), [self.a3])
user_1_from_db.username = "Paul"
self.a3.authors.set([user_2.username])
user_1_from_db.save()
# Assign a different article.
self.a4.authors.add(user_1_from_db.username)
self.assertSequenceEqual(user_1_from_db.article_set.all(), [self.a4])
# Refresh the instance with an evaluated related manager.
user_1.refresh_from_db()
self.assertEqual(user_1.username, "Paul")
self.assertSequenceEqual(user_1.article_set.all(), [self.a4])
def test_add_remove_invalid_type(self):
msg = "Field 'id' expected a number but got 'invalid'."
for method in ["add", "remove"]: