diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-09-30 18:18:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-30 18:18:33 +0200 |
commit | 5e0aa362d91d000984995ce374c2d7547d8d107f (patch) | |
tree | cb81db29ee76b4c0bb235366de83c130d8dddfaa /tests/custom_managers | |
parent | 6cc0f22a73970dd7c0d29d4d8d2ff9e1cc862b30 (diff) | |
download | django-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/custom_managers')
-rw-r--r-- | tests/custom_managers/models.py | 16 | ||||
-rw-r--r-- | tests/custom_managers/tests.py | 76 |
2 files changed, 0 insertions, 92 deletions
diff --git a/tests/custom_managers/models.py b/tests/custom_managers/models.py index 56448b45e9..53a07c462d 100644 --- a/tests/custom_managers/models.py +++ b/tests/custom_managers/models.py @@ -164,22 +164,6 @@ class Book(models.Model): base_manager_name = "annotated_objects" -class ConfusedBook(models.Model): - title = models.CharField(max_length=50) - author = models.CharField(max_length=30) - favorite_things = GenericRelation( - Person, - content_type_field="favorite_thing_type", - object_id_field="favorite_thing_id", - ) - less_favorite_things = GenericRelation( - FunPerson, - content_type_field="favorite_thing_type", - object_id_field="favorite_thing_id", - related_query_name="favorite_things", - ) - - class FastCarManager(models.Manager): def get_queryset(self): return super().get_queryset().filter(top_speed__gt=150) diff --git a/tests/custom_managers/tests.py b/tests/custom_managers/tests.py index 6b90a6ce37..5ae5c719d8 100644 --- a/tests/custom_managers/tests.py +++ b/tests/custom_managers/tests.py @@ -4,7 +4,6 @@ from django.test import TestCase from .models import ( Book, Car, - ConfusedBook, CustomManager, CustomQuerySet, DeconstructibleCustomManager, @@ -196,10 +195,6 @@ class CustomManagerTests(TestCase): ordered=False, ) - def test_fk_related_manager_reused(self): - self.assertIs(self.b1.favorite_books, self.b1.favorite_books) - self.assertIn("favorite_books", self.b1._state.related_managers_cache) - def test_gfk_related_manager(self): Person.objects.create( first_name="Bugs", last_name="Bunny", fun=True, favorite_thing=self.b1 @@ -248,67 +243,6 @@ class CustomManagerTests(TestCase): ordered=False, ) - def test_gfk_related_manager_reused(self): - self.assertIs( - self.b1.fun_people_favorite_things, - self.b1.fun_people_favorite_things, - ) - self.assertIn( - "fun_people_favorite_things", - self.b1._state.related_managers_cache, - ) - - def test_gfk_related_manager_not_reused_when_alternate(self): - self.assertIsNot( - self.b1.favorite_things(manager="fun_people"), - self.b1.favorite_things(manager="fun_people"), - ) - - def test_gfk_related_manager_no_overlap_when_not_hidden(self): - """ - If a GenericRelation defines a related_query_name (and thus the - related_name) which shadows another GenericRelation, it should not - cause those separate managers to clash. - """ - book = ConfusedBook.objects.create( - title="How to program", - author="Rodney Dangerfield", - ) - person = Person.objects.create( - first_name="Bugs", - last_name="Bunny", - fun=True, - favorite_thing=book, - ) - fun_person = FunPerson.objects.create( - first_name="Droopy", - last_name="Dog", - fun=False, - favorite_thing=book, - ) - # The managers don't collide in the internal cache. - self.assertIsNot(book.favorite_things, book.less_favorite_things) - self.assertIs(book.favorite_things, book.favorite_things) - self.assertIs(book.less_favorite_things, book.less_favorite_things) - # Both managers are cached separately despite the collision in names. - self.assertIn("favorite_things", book._state.related_managers_cache) - self.assertIn("less_favorite_things", book._state.related_managers_cache) - # "less_favorite_things" isn't available as a reverse related manager, - # so never ends up in the cache. - self.assertQuerysetEqual(fun_person.favorite_things.all(), [book]) - with self.assertRaises(AttributeError): - fun_person.less_favorite_things - self.assertIn("favorite_things", fun_person._state.related_managers_cache) - self.assertNotIn( - "less_favorite_things", - fun_person._state.related_managers_cache, - ) - # The GenericRelation doesn't exist for Person, only FunPerson, so the - # exception prevents the cache from being polluted. - with self.assertRaises(AttributeError): - person.favorite_things - self.assertNotIn("favorite_things", person._state.related_managers_cache) - def test_m2m_related_manager(self): bugs = Person.objects.create(first_name="Bugs", last_name="Bunny", fun=True) self.b1.authors.add(bugs) @@ -355,16 +289,6 @@ class CustomManagerTests(TestCase): ordered=False, ) - def test_m2m_related_forward_manager_reused(self): - self.assertIs(self.b1.authors, self.b1.authors) - self.assertIn("authors", self.b1._state.related_managers_cache) - - def test_m2m_related_revers_manager_reused(self): - bugs = Person.objects.create(first_name="Bugs", last_name="Bunny") - self.b1.authors.add(bugs) - self.assertIs(bugs.books, bugs.books) - self.assertIn("books", bugs._state.related_managers_cache) - def test_removal_through_default_fk_related_manager(self, bulk=True): bugs = FunPerson.objects.create( first_name="Bugs", last_name="Bunny", fun=True, favorite_book=self.b1 |