diff options
| author | Attila Tovt <uran198@gmail.com> | 2016-02-26 07:28:48 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-02-26 19:26:15 -0500 |
| commit | 5e2c4d7afbaeec196aedb9888a47e0b635ff55d4 (patch) | |
| tree | 16d01ef0d5c23894118ea5b0cb170745201e556b /django | |
| parent | 3389c5ea229884a1943873fe7e7ffc2800cefc22 (diff) | |
Fixed #26264 -- Fixed prefetch_related() crashes with values_list(flat=True)
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/query.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index 82074d700b..ace55a5da2 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -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: |
