Fixed #29320 -- Added an exception when an annotation alias matches a ForeignKey attname.

This commit is contained in:
Flávio Juvenal 2018-04-12 15:06:43 -03:00 committed by Tim Graham
parent 78f8b80f9b
commit e1f13f1551
2 changed files with 10 additions and 1 deletions

View file

@ -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: