1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #35309 -- Made prefetch clear ordering for single-valued relationships.

This commit is contained in:
Laurent Lyaudet
2024-03-16 06:51:38 +01:00
committed by Mariusz Felisiak
parent 921670c694
commit f2388a4b73
2 changed files with 75 additions and 3 deletions

View File

@@ -195,6 +195,9 @@ class ForwardManyToOneDescriptor:
else:
query = {"%s__in" % self.field.related_query_name(): instances}
queryset = queryset.filter(**query)
# There can be only one object prefetched for each instance so clear
# ordering if the query allows it without side effects.
queryset.query.clear_ordering()
# Since we're going to assign directly in the cache,
# we must manage the reverse relation cache manually.
@@ -469,6 +472,9 @@ class ReverseOneToOneDescriptor:
instances_dict = {instance_attr(inst): inst for inst in instances}
query = {"%s__in" % self.related.field.name: instances}
queryset = queryset.filter(**query)
# There can be only one object prefetched for each instance so clear
# ordering if the query allows it without side effects.
queryset.query.clear_ordering()
# Since we're going to assign directly in the cache,
# we must manage the reverse relation cache manually.