Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refs #11256 -- Extended the annotation field name conflict check to c…

…over m2ms and reverse related descriptors as well. This is needed to actually cover the case raised by #14373.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14116 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2f17dd3dd0fdcecf179375af32983a952bd7dfd9 1 parent ace6519
Carl Meyer carljm authored
2  django/db/models/query.py
View
@@ -625,7 +625,7 @@ def annotate(self, *args, **kwargs):
% arg.default_alias)
kwargs[arg.default_alias] = arg
- names = set([f.name for f in self.model._meta.fields])
+ names = set(self.model._meta.get_all_field_names())
for aggregate in kwargs:
if aggregate in names:
raise ValueError("The %s annotation conflicts with a field on "
8 tests/regressiontests/aggregation_regress/tests.py
View
@@ -489,6 +489,14 @@ def test_field_name_conflict(self):
# Regression for #11256 - providing an aggregate name that conflicts with a field name on the model raises ValueError
self.assertRaises(ValueError, Author.objects.annotate, age=Avg('friends__age'))
+ def test_m2m_name_conflict(self):
+ # Regression for #11256 - providing an aggregate name that conflicts with an m2m name on the model raises ValueError
+ self.assertRaises(ValueError, Author.objects.annotate, friends=Count('friends'))
+
+ def test_reverse_relation_name_conflict(self):
+ # Regression for #11256 - providing an aggregate name that conflicts with a reverse-related name on the model raises ValueError
+ self.assertRaises(ValueError, Author.objects.annotate, book_contact_set=Avg('friends__age'))
+
def test_pickle(self):
# Regression for #10197 -- Queries with aggregates can be pickled.
# First check that pickling is possible at all. No crash = success
Please sign in to comment.
Something went wrong with that request. Please try again.