summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorFlávio Juvenal <flaviojuvenal@gmail.com>2018-04-12 15:06:43 -0300
committerTim Graham <timograham@gmail.com>2018-04-12 21:15:40 -0400
commite1f13f15512ece2d8ea8c7bf9f704ce4286c2ffa (patch)
tree702ee34597c8ffdbf2dcc28cada606beb9f63f7b /django/db
parent78f8b80f9b215e50618375adce4c97795dabbb84 (diff)
Fixed #29320 -- Added an exception when an annotation alias matches a ForeignKey attname.
Diffstat (limited to 'django/db')
-rw-r--r--django/db/models/query.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 71ebf660c7..2db6690c44 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -7,6 +7,7 @@ import operator
import warnings
from collections import OrderedDict, namedtuple
from functools import lru_cache
+from itertools import chain
from django.conf import settings
from django.core import exceptions
@@ -981,7 +982,10 @@ class QuerySet:
clone = self._chain()
names = self._fields
if names is None:
- names = {f.name for f in self.model._meta.get_fields()}
+ names = set(chain.from_iterable(
+ (field.name, field.attname) if hasattr(field, 'attname') else (field.name,)
+ for field in self.model._meta.get_fields()
+ ))
for alias, annotation in annotations.items():
if alias in names: