diff options
Diffstat (limited to 'tests/aggregation')
| -rw-r--r-- | tests/aggregation/models.py | 1 | ||||
| -rw-r--r-- | tests/aggregation/tests.py | 16 |
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 95b77ef87b..a8377c9a26 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1191,6 +1191,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' and 'ONLY_FULL_GROUP_BY' in connection.sql_mode, |
