Skip to content

Instantly share code, notes, and snippets.

@loic
Created January 30, 2015 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loic/4b9f9b21fb54e2813f78 to your computer and use it in GitHub Desktop.
Save loic/4b9f9b21fb54e2813f78 to your computer and use it in GitHub Desktop.
diff --git a/django/db/models/query.py b/django/db/models/query.py
index ef0c2db..20edcd6 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -886,16 +886,14 @@ class QuerySet(object):
if names is None:
names = {f.name for f in self.model._meta.get_fields()}
+ added_aggregates = False
for alias, annotation in annotations.items():
if alias in names:
raise ValueError("The annotation '%s' conflicts with a field on "
"the model." % alias)
clone.query.add_annotation(annotation, alias, is_summary=False)
-
- added_aggregates = []
- for alias, annotation in clone.query.annotations.items():
- if alias in annotations and annotation.contains_aggregate:
- added_aggregates.append(alias)
+ if annotation.contains_aggregate:
+ added_aggregates = True
if added_aggregates:
if clone._fields is None:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment