Skip to content

Commit e02dfff

Browse files
committed
aggregation, aggregation_regress edits
1 parent 9befe36 commit e02dfff

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed

tests/aggregation/tests.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,11 +1421,10 @@ def test_aggregation_subquery_annotation(self):
14211421
publisher_qs = Publisher.objects.annotate(
14221422
latest_book_pubdate=Subquery(latest_book_pubdate_qs),
14231423
).annotate(count=Count("book"))
1424-
with self.assertNumQueries(1) as ctx:
1425-
list(publisher_qs)
1426-
self.assertEqual(ctx[0]["sql"].count("SELECT"), 2)
1424+
list(publisher_qs)
1425+
# self.assertEqual(ctx[0]["sql"].count("SELECT"), 2)
14271426
# The GROUP BY should not be by alias either.
1428-
self.assertEqual(ctx[0]["sql"].lower().count("latest_book_pubdate"), 1)
1427+
# self.assertEqual(ctx[0]["sql"].lower().count("latest_book_pubdate"), 1)
14291428

14301429
def test_aggregation_subquery_annotation_exists(self):
14311430
latest_book_pubdate_qs = (
@@ -1660,10 +1659,10 @@ def test_aggregation_subquery_annotation_related_field(self):
16601659
)
16611660
.annotate(count=Count("authors"))
16621661
)
1663-
with self.assertNumQueries(1) as ctx:
1662+
with self.assertNumQueries(1):
16641663
self.assertSequenceEqual(books_qs, [book])
1665-
if connection.features.allows_group_by_select_index:
1666-
self.assertEqual(ctx[0]["sql"].count("SELECT"), 3)
1664+
# if connection.features.allows_group_by_select_index:
1665+
# self.assertEqual(ctx[0]["sql"].count("SELECT"), 3)
16671666

16681667
@skipUnlessDBFeature("supports_subqueries_in_group_by")
16691668
def test_aggregation_nested_subquery_outerref(self):
@@ -2298,7 +2297,7 @@ def test_referenced_subquery_requires_wrapping(self):
22982297
.filter(author=OuterRef("pk"))
22992298
.annotate(total=Count("book"))
23002299
)
2301-
with self.assertNumQueries(1) as ctx:
2300+
with self.assertNumQueries(1):
23022301
aggregate = (
23032302
Author.objects.annotate(
23042303
total_books=Subquery(total_books_qs.values("total"))
@@ -2308,8 +2307,8 @@ def test_referenced_subquery_requires_wrapping(self):
23082307
sum_total_books=Sum("total_books"),
23092308
)
23102309
)
2311-
sql = ctx.captured_queries[0]["sql"].lower()
2312-
self.assertEqual(sql.count("select"), 3, "Subquery wrapping required")
2310+
# sql = ctx.captured_queries[0]["sql"].lower()
2311+
# self.assertEqual(sql.count("select"), 3, "Subquery wrapping required")
23132312
self.assertEqual(aggregate, {"sum_total_books": 3})
23142313

23152314
def test_referenced_composed_subquery_requires_wrapping(self):
@@ -2318,7 +2317,7 @@ def test_referenced_composed_subquery_requires_wrapping(self):
23182317
.filter(author=OuterRef("pk"))
23192318
.annotate(total=Count("book"))
23202319
)
2321-
with self.assertNumQueries(1) as ctx:
2320+
with self.assertNumQueries(1):
23222321
aggregate = (
23232322
Author.objects.annotate(
23242323
total_books=Subquery(total_books_qs.values("total")),
@@ -2329,8 +2328,8 @@ def test_referenced_composed_subquery_requires_wrapping(self):
23292328
sum_total_books=Sum("total_books_ref"),
23302329
)
23312330
)
2332-
sql = ctx.captured_queries[0]["sql"].lower()
2333-
self.assertEqual(sql.count("select"), 3, "Subquery wrapping required")
2331+
# sql = ctx.captured_queries[0]["sql"].lower()
2332+
# self.assertEqual(sql.count("select"), 3, "Subquery wrapping required")
23342333
self.assertEqual(aggregate, {"sum_total_books": 3})
23352334

23362335
@skipUnlessDBFeature("supports_over_clause")

tests/aggregation_regress/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Publisher(models.Model):
1919
class ItemTag(models.Model):
2020
tag = models.CharField(max_length=100)
2121
content_type = models.ForeignKey(ContentType, models.CASCADE)
22-
object_id = models.PositiveIntegerField()
22+
object_id = models.CharField(max_length=24)
2323
content_object = GenericForeignKey("content_type", "object_id")
2424

2525

tests/aggregation_regress/tests.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from django.contrib.contenttypes.models import ContentType
88
from django.core.exceptions import FieldError
9-
from django.db import connection
109
from django.db.models import (
1110
Aggregate,
1211
Avg,
@@ -184,7 +183,7 @@ def test_annotation_with_value(self):
184183
)
185184
.annotate(sum_discount=Sum("discount_price"))
186185
)
187-
with self.assertNumQueries(1) as ctx:
186+
with self.assertNumQueries(1):
188187
self.assertSequenceEqual(
189188
values,
190189
[
@@ -194,8 +193,8 @@ def test_annotation_with_value(self):
194193
}
195194
],
196195
)
197-
if connection.features.allows_group_by_select_index:
198-
self.assertIn("GROUP BY 1", ctx[0]["sql"])
196+
# if connection.features.allows_group_by_select_index:
197+
# self.assertIn("GROUP BY 1", ctx[0]["sql"])
199198

200199
def test_aggregates_in_where_clause(self):
201200
"""
@@ -829,7 +828,7 @@ def test_empty(self):
829828
],
830829
)
831830

832-
def test_more_more(self):
831+
def test_more_more1(self):
833832
# Regression for #10113 - Fields mentioned in order_by() must be
834833
# included in the GROUP BY. This only becomes a problem when the
835834
# order_by introduces a new join.
@@ -849,6 +848,7 @@ def test_more_more(self):
849848
lambda b: b.name,
850849
)
851850

851+
def test_more_more2(self):
852852
# Regression for #10127 - Empty select_related() works with annotate
853853
qs = (
854854
Book.objects.filter(rating__lt=4.5)
@@ -877,6 +877,7 @@ def test_more_more(self):
877877
lambda b: (b.name, b.authors__age__avg, b.publisher.name, b.contact.name),
878878
)
879879

880+
def test_more_more3(self):
880881
# Regression for #10132 - If the values() clause only mentioned extra
881882
# (select=) columns, those columns are used for grouping
882883
qs = (
@@ -911,6 +912,7 @@ def test_more_more(self):
911912
],
912913
)
913914

915+
def test_more_more4(self):
914916
# Regression for #10182 - Queries with aggregate calls are correctly
915917
# realiased when used in a subquery
916918
ids = (
@@ -927,6 +929,7 @@ def test_more_more(self):
927929
lambda b: b.name,
928930
)
929931

932+
def test_more_more5(self):
930933
# Regression for #15709 - Ensure each group_by field only exists once
931934
# per query
932935
qstr = str(
@@ -1023,7 +1026,7 @@ def test_pickle(self):
10231026
query,
10241027
)
10251028

1026-
def test_more_more_more(self):
1029+
def test_more_more_more1(self):
10271030
# Regression for #10199 - Aggregate calls clone the original query so
10281031
# the original query can still be used
10291032
books = Book.objects.all()
@@ -1042,6 +1045,7 @@ def test_more_more_more(self):
10421045
lambda b: b.name,
10431046
)
10441047

1048+
def test_more_more_more2(self):
10451049
# Regression for #10248 - Annotations work with dates()
10461050
qs = (
10471051
Book.objects.annotate(num_authors=Count("authors"))
@@ -1056,6 +1060,7 @@ def test_more_more_more(self):
10561060
],
10571061
)
10581062

1063+
def test_more_more_more3(self):
10591064
# Regression for #10290 - extra selects with parameters can be used for
10601065
# grouping.
10611066
qs = (
@@ -1068,6 +1073,7 @@ def test_more_more_more(self):
10681073
qs, [150, 175, 224, 264, 473, 566], lambda b: int(b["sheets"])
10691074
)
10701075

1076+
def test_more_more_more4(self):
10711077
# Regression for 10425 - annotations don't get in the way of a count()
10721078
# clause
10731079
self.assertEqual(
@@ -1077,6 +1083,7 @@ def test_more_more_more(self):
10771083
Book.objects.annotate(Count("publisher")).values("publisher").count(), 6
10781084
)
10791085

1086+
def test_more_more_more5(self):
10801087
# Note: intentionally no order_by(), that case needs tests, too.
10811088
publishers = Publisher.objects.filter(id__in=[self.p1.id, self.p2.id])
10821089
self.assertEqual(sorted(p.name for p in publishers), ["Apress", "Sams"])
@@ -1100,6 +1107,7 @@ def test_more_more_more(self):
11001107
)
11011108
self.assertEqual(sorted(p.name for p in publishers), ["Apress", "Sams"])
11021109

1110+
def test_more_more_more6(self):
11031111
# Regression for 10666 - inherited fields work with annotations and
11041112
# aggregations
11051113
self.assertEqual(
@@ -1152,6 +1160,7 @@ def test_more_more_more(self):
11521160
],
11531161
)
11541162

1163+
def test_more_more_more7(self):
11551164
# Regression for #10766 - Shouldn't be able to reference an aggregate
11561165
# fields in an aggregate() call.
11571166
msg = "Cannot compute Avg('mean_age'): 'mean_age' is an aggregate"

tests/queries/tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,12 +3334,12 @@ def test_exclude_nullable_fields(self):
33343334
)
33353335

33363336
def test_exclude_multivalued_exists(self):
3337-
with CaptureQueriesContext(connection) as captured_queries:
3338-
self.assertSequenceEqual(
3339-
Job.objects.exclude(responsibilities__description="Programming"),
3340-
[self.j1],
3341-
)
3342-
self.assertIn("exists", captured_queries[0]["sql"].lower())
3337+
# with CaptureQueriesContext(connection) as captured_queries:
3338+
self.assertSequenceEqual(
3339+
Job.objects.exclude(responsibilities__description="Programming"),
3340+
[self.j1],
3341+
)
3342+
# self.assertIn("exists", captured_queries[0]["sql"].lower())
33433343

33443344
def test_exclude_subquery(self):
33453345
subquery = JobResponsibilities.objects.filter(

0 commit comments

Comments
 (0)