summaryrefslogtreecommitdiff
path: root/tests/aggregation
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2020-03-19 19:54:36 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-03-25 09:49:51 +0100
commit72652bcb1b29710d23c3e6f872046d4aedc58665 (patch)
tree0e789a048ed59e44547017f7e0e8e1a15e0ec48b /tests/aggregation
parent600d7d86931e314837591a227c834803f2b4994b (diff)
[3.0.x] Fixed #31377 -- Disabled grouping by aliases on QuerySet.values()/values_list() when they collide with field names.
Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Thanks Holovashchenko Vadym for the report. Backport of 10866a10fe9f0ad3ffdf6f93823aaf4716e6f27c from master
Diffstat (limited to 'tests/aggregation')
-rw-r--r--tests/aggregation/models.py1
-rw-r--r--tests/aggregation/tests.py16
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/aggregation/models.py b/tests/aggregation/models.py
index fd441fe51d..cfc261abcc 100644
--- a/tests/aggregation/models.py
+++ b/tests/aggregation/models.py
@@ -5,6 +5,7 @@ class Author(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()
friends = models.ManyToManyField('self', blank=True)
+ rating = models.FloatField(null=True)
def __str__(self):
return self.name
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index 342507da01..8791221e6b 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -1190,6 +1190,22 @@ class AggregateTestCase(TestCase):
},
])
+ def test_aggregation_subquery_annotation_values_collision(self):
+ books_rating_qs = Book.objects.filter(
+ publisher=OuterRef('pk'),
+ price=Decimal('29.69'),
+ ).values('rating')
+ publisher_qs = Publisher.objects.filter(
+ book__contact__age__gt=20,
+ name=self.p1.name,
+ ).annotate(
+ rating=Subquery(books_rating_qs),
+ contacts_count=Count('book__contact'),
+ ).values('rating').annotate(total_count=Count('rating'))
+ self.assertEqual(list(publisher_qs), [
+ {'rating': 4.0, 'total_count': 2},
+ ])
+
@skipUnlessDBFeature('supports_subqueries_in_group_by')
@skipIf(
connection.vendor == 'mysql',