mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #26264 -- Fixed prefetch_related() crashes with values_list(flat=True)
This commit is contained in:
parent
3389c5ea22
commit
5e2c4d7afb
2 changed files with 17 additions and 5 deletions
|
@ -1421,11 +1421,12 @@ def prefetch_related_objects(model_instances, *related_lookups):
|
|||
if not hasattr(obj, '_prefetched_objects_cache'):
|
||||
try:
|
||||
obj._prefetched_objects_cache = {}
|
||||
except AttributeError:
|
||||
# Must be in a QuerySet subclass that is not returning
|
||||
# Model instances, either in Django or 3rd
|
||||
# party. prefetch_related() doesn't make sense, so quit
|
||||
# now.
|
||||
except (AttributeError, TypeError):
|
||||
# Must be an immutable object from
|
||||
# values_list(flat=True), for example (TypeError) or
|
||||
# a QuerySet subclass that isn't returning Model
|
||||
# instances (AttributeError), either in Django or a 3rd
|
||||
# party. prefetch_related() doesn't make sense, so quit.
|
||||
good_objects = False
|
||||
break
|
||||
if not good_objects:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue