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

Refs #33651 -- Removed Prefetch.get_current_queryset() and get_prefetch_queryset() per deprecation timeline.

This commit is contained in:
Sarah Boyce
2024-12-12 18:12:23 +01:00
parent 55f71b195b
commit 817bc5800b
9 changed files with 21 additions and 252 deletions

View File

@@ -33,7 +33,6 @@ from django.db.models.utils import (
resolve_callables,
)
from django.utils import timezone
from django.utils.deprecation import RemovedInDjango60Warning
from django.utils.functional import cached_property, partition
# The maximum number of results to fetch in a get() query.
@@ -2239,16 +2238,6 @@ class Prefetch:
as_attr = self.to_attr and level == len(parts) - 1
return to_attr, as_attr
def get_current_queryset(self, level):
warnings.warn(
"Prefetch.get_current_queryset() is deprecated. Use "
"get_current_querysets() instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
querysets = self.get_current_querysets(level)
return querysets[0] if querysets is not None else None
def get_current_querysets(self, level):
if (
self.get_current_prefetch_to(level) == self.prefetch_to
@@ -2480,11 +2469,7 @@ def get_prefetcher(instance, through_attr, to_attr):
if rel_obj_descriptor:
# singly related object, descriptor object has the
# get_prefetch_querysets() method.
if (
hasattr(rel_obj_descriptor, "get_prefetch_querysets")
# RemovedInDjango60Warning.
or hasattr(rel_obj_descriptor, "get_prefetch_queryset")
):
if hasattr(rel_obj_descriptor, "get_prefetch_querysets"):
prefetcher = rel_obj_descriptor
# If to_attr is set, check if the value has already been set,
# which is done with has_to_attr_attribute(). Do not use the
@@ -2497,11 +2482,7 @@ def get_prefetcher(instance, through_attr, to_attr):
# the attribute on the instance rather than the class to
# support many related managers
rel_obj = getattr(instance, through_attr)
if (
hasattr(rel_obj, "get_prefetch_querysets")
# RemovedInDjango60Warning.
or hasattr(rel_obj, "get_prefetch_queryset")
):
if hasattr(rel_obj, "get_prefetch_querysets"):
prefetcher = rel_obj
if through_attr == to_attr:
@@ -2534,36 +2515,16 @@ def prefetch_one_level(instances, prefetcher, lookup, level):
# The 'values to be matched' must be hashable as they will be used
# in a dictionary.
if hasattr(prefetcher, "get_prefetch_querysets"):
(
rel_qs,
rel_obj_attr,
instance_attr,
single,
cache_name,
is_descriptor,
) = prefetcher.get_prefetch_querysets(
instances, lookup.get_current_querysets(level)
)
else:
warnings.warn(
"The usage of get_prefetch_queryset() in prefetch_related_objects() is "
"deprecated. Implement get_prefetch_querysets() instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
queryset = None
if querysets := lookup.get_current_querysets(level):
queryset = querysets[0]
(
rel_qs,
rel_obj_attr,
instance_attr,
single,
cache_name,
is_descriptor,
) = prefetcher.get_prefetch_queryset(instances, queryset)
(
rel_qs,
rel_obj_attr,
instance_attr,
single,
cache_name,
is_descriptor,
) = prefetcher.get_prefetch_querysets(
instances, lookup.get_current_querysets(level)
)
# We have to handle the possibility that the QuerySet we just got back
# contains some prefetch_related lookups. We don't want to trigger the
# prefetch_related functionality by evaluating the query. Rather, we need