Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Refs #11256 -- Extended the annotation field name conflict ch…

…eck to cover m2ms and reverse related descriptors as well. This is needed to actually cover the case raised by #14373. Backport of [14116].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14117 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 700c5a3dfe46155ae367345eb4e7a04013bb6548 1 parent 4395b65
Carl Meyer authored October 10, 2010
2  django/db/models/query.py
@@ -625,7 +625,7 @@ def annotate(self, *args, **kwargs):
625 625
                                  % arg.default_alias)
626 626
             kwargs[arg.default_alias] = arg
627 627
 
628  
-        names = set([f.name for f in self.model._meta.fields])
  628
+        names = set(self.model._meta.get_all_field_names())
629 629
         for aggregate in kwargs:
630 630
             if aggregate in names:
631 631
                 raise ValueError("The %s annotation conflicts with a field on "
8  tests/regressiontests/aggregation_regress/tests.py
@@ -489,6 +489,14 @@ def test_field_name_conflict(self):
489 489
         # Regression for #11256 - providing an aggregate name that conflicts with a field name on the model raises ValueError
490 490
         self.assertRaises(ValueError, Author.objects.annotate, age=Avg('friends__age'))
491 491
 
  492
+    def test_m2m_name_conflict(self):
  493
+        # Regression for #11256 - providing an aggregate name that conflicts with an m2m name on the model raises ValueError
  494
+        self.assertRaises(ValueError, Author.objects.annotate, friends=Count('friends'))
  495
+
  496
+    def test_reverse_relation_name_conflict(self):
  497
+        # Regression for #11256 - providing an aggregate name that conflicts with a reverse-related name on the model raises ValueError
  498
+        self.assertRaises(ValueError, Author.objects.annotate, book_contact_set=Avg('friends__age'))
  499
+
492 500
     def test_pickle(self):
493 501
         # Regression for #10197 -- Queries with aggregates can be pickled.
494 502
         # First check that pickling is possible at all. No crash = success

0 notes on commit 700c5a3

Please sign in to comment.
Something went wrong with that request. Please try again.