diff options
| author | Lex Berezhny <lex@damoti.com> | 2017-01-31 18:45:55 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-01-31 18:46:07 -0500 |
| commit | d43f8478478c333ed8b7e499abef17a86363d61c (patch) | |
| tree | 469745e06458ab1727c58985030bd80e14d99067 /django | |
| parent | 8afe790df91faf45f13bccbb69310b45afcb1b30 (diff) | |
[1.11.x] Fixed #27800 -- Fixed QuerySet.annotate(Length(...)).distinct() crash.
Backport of ac5f886c5610a6bca26dab10170b445d1e9df450 from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/sql/query.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 5f65786373..695e52cda7 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1345,7 +1345,12 @@ class Query(object): "querying. If it is a GenericForeignKey, consider " "adding a GenericRelation." % name ) - model = field.model._meta.concrete_model + try: + model = field.model._meta.concrete_model + except AttributeError: + # QuerySet.annotate() may introduce fields that aren't + # attached to a model. + model = None else: # We didn't find the current field, so move position back # one step. |
