summaryrefslogtreecommitdiff
path: root/tests/many_to_many
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-09-30 18:18:33 +0200
committerGitHub <noreply@github.com>2022-09-30 18:18:33 +0200
commit5e0aa362d91d000984995ce374c2d7547d8d107f (patch)
treecb81db29ee76b4c0bb235366de83c130d8dddfaa /tests/many_to_many
parent6cc0f22a73970dd7c0d29d4d8d2ff9e1cc862b30 (diff)
downloaddjango-5e0aa362d91d000984995ce374c2d7547d8d107f.tar.gz
Fixed #33984 -- Reverted "Fixed #32980 -- Made models cache related managers."
This reverts 4f8c7fd9d91b35e2c2922de4bb50c8c8066cbbc6 and adds two regression tests: - test_related_manager_refresh(), and - test_create_copy_with_m2m(). Thanks joeli for the report.
Diffstat (limited to 'tests/many_to_many')
-rw-r--r--tests/many_to_many/tests.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py
index 53e870ddad..729f011446 100644
--- a/tests/many_to_many/tests.py
+++ b/tests/many_to_many/tests.py
@@ -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"]: