From 5e0aa362d91d000984995ce374c2d7547d8d107f Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 30 Sep 2022 18:18:33 +0200 Subject: 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. --- tests/m2m_regress/tests.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'tests/m2m_regress') diff --git a/tests/m2m_regress/tests.py b/tests/m2m_regress/tests.py index d5ad559e85..d3f352ffd9 100644 --- a/tests/m2m_regress/tests.py +++ b/tests/m2m_regress/tests.py @@ -39,14 +39,6 @@ class M2MRegressionTests(TestCase): self.assertSequenceEqual(e1.topics.all(), [t1]) self.assertSequenceEqual(e1.related.all(), [t2]) - def test_m2m_managers_reused(self): - s1 = SelfRefer.objects.create(name="s1") - e1 = Entry.objects.create(name="e1") - self.assertIs(s1.references, s1.references) - self.assertIs(s1.related, s1.related) - self.assertIs(e1.topics, e1.topics) - self.assertIs(e1.related, e1.related) - def test_internal_related_name_not_in_error_msg(self): # The secret internal related names for self-referential many-to-many # fields shouldn't appear in the list when an error is made. @@ -79,6 +71,20 @@ class M2MRegressionTests(TestCase): w.save() w.delete() + def test_create_copy_with_m2m(self): + t1 = Tag.objects.create(name="t1") + Entry.objects.create(name="e1") + entry = Entry.objects.first() + entry.topics.set([t1]) + old_topics = entry.topics.all() + entry.pk = None + entry._state.adding = True + entry.save() + entry.topics.set(old_topics) + entry = Entry.objects.get(pk=entry.pk) + self.assertCountEqual(entry.topics.all(), old_topics) + self.assertSequenceEqual(entry.topics.all(), [t1]) + def test_add_m2m_with_base_class(self): # Regression for #11956 -- You can add an object to a m2m with the # base class without causing integrity errors -- cgit v1.3