summaryrefslogtreecommitdiff
path: root/django/contrib/contenttypes
diff options
context:
space:
mode:
authorKeryn Knight <keryn@kerynknight.com>2026-01-10 08:39:45 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2026-03-11 18:05:44 +0100
commit804607df0e174c524a3ea880b8ecbb555ecb4abb (patch)
tree8d602a76d9cdcbec2357a96588e68886bb3bd705 /django/contrib/contenttypes
parent8d8a8713432a88737c4400610eef11c5c8457b86 (diff)
Refs #28455 -- Avoided QuerySet cloning in simple prefetch_related() usages.
manager.get_queryset() always returns freshly instantiated per-instance QuerySet which doesn't need subsequent cloning. Based on work originally done by Anssi Kääriäinen and Tim Graham.
Diffstat (limited to 'django/contrib/contenttypes')
-rw-r--r--django/contrib/contenttypes/fields.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py
index 300fec4289..0d7ef0f256 100644
--- a/django/contrib/contenttypes/fields.py
+++ b/django/contrib/contenttypes/fields.py
@@ -651,11 +651,12 @@ def create_generic_related_manager(superclass, rel):
Filter the queryset for the instance this manager is bound to.
"""
db = self._db or router.db_for_read(self.model, instance=self.instance)
- return (
- queryset.using(db)
- .fetch_mode(self.instance._state.fetch_mode)
- .filter(**self.core_filters)
- )
+ with queryset._avoid_cloning():
+ return (
+ queryset.using(db)
+ .fetch_mode(self.instance._state.fetch_mode)
+ .filter(**self.core_filters)
+ )
def _remove_prefetched_objects(self):
try: