summaryrefslogtreecommitdiff
path: root/tests/aggregation
Commit message (Collapse)AuthorAgeFilesLines
* Fixed #34464 -- Fixed queryset aggregation over group by reference.Simon Charette2023-04-071-0/+7
| | | | | | | | Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7. Refs #28477. Thanks Ian Cubitt for the report.
* Fixed #34255 -- Made PostgreSQL backend use client-side parameters binding ↵Mariusz Felisiak2023-01-171-0/+15
| | | | | | | | with psycopg version 3. Thanks Guillaume Andreu Sabater for the report. Co-authored-by: Florian Apolloner <apollo13@users.noreply.github.com>
* Fixed #34176 -- Fixed grouping by ambiguous aliases.Simon Charette2023-01-091-9/+9
| | | | | | | | | | | | | | | Regression in b7b28c7c189615543218e81319473888bc46d831. Refs #31377. Thanks Shai Berger for the report and reviews. test_aggregation_subquery_annotation_values_collision() has been updated as queries that are explicitly grouped by a subquery should always be grouped by it and not its outer columns even if its alias collides with referenced table columns. This was not possible to accomplish at the time 10866a10 landed because we didn't have compiler level handling of colliding aliases.
* Removed unnecessary commas in tests.Mariusz Felisiak2022-12-212-2/+2
|
* Fixed #31679 -- Delayed annotating aggregations.Simon Charette2022-11-231-4/+12
| | | | | | | | | | By avoiding to annotate aggregations meant to be possibly pushed to an outer query until their references are resolved it is possible to aggregate over a query with the same alias. Even if #34176 is a convoluted case to support, this refactor seems worth it given the reduction in complexity it brings with regards to annotation removal when performing a subquery pushdown.
* Refs #28477 -- Fixed handling aliased annotations on aggregation.Simon Charette2022-11-141-3/+32
| | | | | | | | | | Just like when using .annotate(), the .alias() method will generate the necessary JOINs to resolve the alias even if not selected. Since these JOINs could be multi-valued non-selected aggregates must be considered to require subquery wrapping as a GROUP BY is required to combine duplicated tuples from the base table. Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7.
* Fixed #28477 -- Stripped unused annotations on aggregation.Simon Charette2022-11-091-0/+39
| | | | | Also avoid an unnecessary pushdown when aggregating over a query that doesn't have aggregate annotations.
* Refs #27849 -- Fixed filtered aggregates crash on filters that match everything.Simon Charette2022-11-071-0/+13
|
* Refs #27849 -- Added test for filtered aggregates with empty conditions.Simon Charette2022-11-071-0/+13
|
* Refs #33990 -- Renamed TransactionTestCase.assertQuerysetEqual() to ↵Gregor Gärtner2022-10-081-27/+27
| | | | | | assertQuerySetEqual(). Co-Authored-By: Michael Howitz <mh@gocept.com>
* Replaced assertQuerysetEqual() to assertSequenceEqual()/assertCountEqual() ↵Mariusz Felisiak2022-10-071-1/+1
| | | | | where appropriate. Follow up to 3f7b3275627385f8f7531fca01cdda50d4ec6b6e.
* Refs #31150 -- Enabled implicit GROUP BY aliases.Simon Charette2022-10-061-6/+6
| | | | | | | This ensures implicit grouping from aggregate function annotations groups by uncollapsed selected aliases if supported. The feature is disabled on Oracle because it doesn't support it.
* Refs #33992 -- Refactored subquery grouping logic.Simon Charette2022-10-061-3/+1
| | | | | | | | | | | This required moving the combined queries slicing logic to the compiler in order to allow Query.exists() to be called at expression resolving time. It allowed for Query.exists() to be called at Exists() initialization time and thus ensured that get_group_by_cols() was operating on the terminal representation of the query that only has a single column selected.
* Fixed #33992 -- Fixed queryset crash when aggregating over a group ↵Simon Charette2022-09-081-0/+11
| | | | | | | | | | | | | containing Exists. A more in-depth solution is likely to make sure that we always GROUP BY selected annotations or revisit how we use Query.exists() in the Exists expression but that requires extra work that isn't suitable for a backport. Regression in e5a92d400acb4ca6a8e1375d1ab8121f2c7220be. Thanks Fernando Flores Villaça for the report.
* Fixed #33718 -- Dropped support for MySQL 5.7.Mariusz Felisiak2022-07-081-3/+3
|
* Fixed #33655 -- Removed unnecessary constant from GROUP BY clause for ↵marcperrinoptel2022-04-261-0/+12
| | | | QuerySet.exists().
* Fixed CVE-2022-28346 -- Protected QuerySet.annotate(), aggregate(), and ↵Mariusz Felisiak2022-04-111-0/+9
| | | | | | | | extra() against SQL injection in column aliases. Thanks Splunk team: Preston Elder, Jacob Davis, Jacob Moore, Matt Hanson, David Briggs, and a security researcher: Danylo Dmytriiev (DDV_UA) for the report.
* Fixed #33397 -- Corrected resolving output_field for ↵Luke Plant2022-03-311-2/+2
| | | | | | | | | | | | | | | | | | DateField/DateTimeField/TimeField/DurationFields. This includes refactoring of CombinedExpression._resolve_output_field() so it no longer uses the behavior inherited from Expression of guessing same output type if argument types match, and instead we explicitly define the output type of all supported operations. This also makes nonsensical operations involving dates (e.g. date + date) raise a FieldError, and adds support for automatically inferring output_field for cases such as: * date - date * date + duration * date - duration * time + duration * time - time
* Refs #32365 -- Removed internal uses of utils.timezone.utc alias.Carlton Gibson2022-03-241-3/+3
| | | | | Remaining test case ensures that uses of the alias are mapped canonically by the migration writer.
* Removed redundant QuerySet.all() calls in docs and tests.Nick Pope2022-02-221-11/+6
| | | | Most QuerySet methods are mapped onto the Manager and, in general, it isn't necessary to call .all() on the manager.
* Refs #33476 -- Refactored code to strictly match 88 characters line length.Mariusz Felisiak2022-02-071-7/+19
|
* Refs #33476 -- Reformatted code with Black.django-bot2022-02-073-769/+1204
|
* Fixed #33468 -- Fixed QuerySet.aggregate() after annotate() crash on ↵Mariusz Felisiak2022-01-311-0/+12
| | | | | aggregates with default. Thanks Adam Johnson for the report.
* Fixed #33282 -- Fixed a crash when OR'ing subquery and aggregation lookups.Simon Charette2021-12-021-4/+30
| | | | | | | | As a QuerySet resolves to Query the outer column references grouping logic should be defined on the latter and proxied from Subquery for the cases where get_group_by_cols is called on unresolved expressions. Thanks Antonio Terceiro for the report and initial patch.
* Fixed #33262 -- Fixed crash of conditional aggregation on Exists().Hannes Ljungberg2021-11-041-0/+8
|
* Fixed #33141 -- Renamed Expression.empty_aggregate_value to ↵David Wobrock2021-09-291-1/+1
| | | | empty_result_set_value.
* Fixed #33073 -- Fixed queryset crash with aggregation and empty/extra ↵David Wobrock2021-09-011-0/+14
| | | | queryset annotation.
* Refs #10929 -- Allowed NowUTC SQL customization for third-party backends.Tim Graham2021-08-241-8/+4
|
* Fixed #10929 -- Added default argument to aggregates.Nick Pope2021-07-191-3/+208
| | | | Thanks to Simon Charette and Adam Johnson for the reviews.
* Refs #26430 -- Re-introduced empty aggregation optimization.Simon Charette2021-07-021-27/+57
| | | | | | | | | | | | The introduction of the Expression.empty_aggregate_value interface allows the compilation stage to enable the EmptyResultSet optimization if all the aggregates expressions implement it. This also removes unnecessary RegrCount/Count.convert_value() methods. Disabling the empty result set aggregation optimization when it wasn't appropriate prevented None returned for a Count aggregation value. Thanks Nick Pope for the review.
* Fixed #26430 -- Fixed coalesced aggregation of empty result sets.Simon Charette2021-07-021-0/+32
| | | | | Disable the EmptyResultSet optimization when performing aggregation as it might interfere with coalescence.
* Fixed #32478 -- Included nested columns referenced by subqueries in GROUP BY ↵Simon Charette2021-02-241-0/+15
| | | | | | | | | | on aggregations. Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Refs #31094, #31150. Thanks Igor Pejic for the report.
* Fixed #32178 -- Allowed database backends to skip tests and mark expected ↵Hasan Ramezani2020-12-101-5/+0
| | | | | failures. Co-authored-by: Tim Graham <timograham@gmail.com>
* Fixed #25534, Fixed #31639 -- Added support for transform references in ↵Ian Foote2020-11-271-0/+8
| | | | | | expressions. Thanks Mariusz Felisiak and Simon Charette for reviews.
* Fixed #31235 -- Made assertQuerysetEqual() compare querysets directly.Hasan Ramezani2020-11-061-6/+6
| | | | | | | | This also replaces assertQuerysetEqual() to assertSequenceEqual()/assertCountEqual() where appropriate. Co-authored-by: Peter Inglesby <peter.inglesby@gmail.com> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
* Fixed #32166 -- Removed redundant definition of Greatest in ↵Sicong2020-11-031-10/+2
| | | | test_expression_on_aggregation.
* Fixed #26390 -- Disabled grouping by Random().Étienne Beaulé2020-10-211-0/+15
| | | | Thanks to Tzu-ping Chung for the tests.
* Fixed #31880 -- Made QuerySet.aggregate() raise FieldError when aggregating ↵David Wobrock2020-09-291-0/+10
| | | | over aggregation aliases.
* Fixed #31888 -- Avoided module-level MySQL queries in tests.Ahmad A. Hussein2020-08-171-6/+5
|
* Refs #30446 -- Removed unnecessary Value(..., output_field) in docs and tests.Simon Charette2020-07-151-1/+1
|
* Fixed #30446 -- Resolved Value.output_field for stdlib types.Simon Charette2020-07-151-5/+1
| | | | | | This required implementing a limited form of dynamic dispatch to combine expressions with numerical output. Refs #26355 should eventually provide a better interface for that.
* Fixed #31568 -- Fixed alias reference when aggregating over multiple subqueries.Simon Charette2020-05-141-1/+22
| | | | | | | | | | | | | 691def10a0197d83d2d108bd9043b0916d0f09b4 made all Subquery() instances equal to each other which broke aggregation subquery pushdown which relied on object equality to determine which alias it should select. Subquery.__eq__() will be fixed in an another commit but Query.rewrite_cols() should haved used object identity from the start. Refs #30727, #30188. Thanks Makina Corpus for the report.
* Fixed #31377 -- Disabled grouping by aliases on ↵Hasan Ramezani2020-03-252-0/+17
| | | | | | | | QuerySet.values()/values_list() when they collide with field names. Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Thanks Holovashchenko Vadym for the report.
* Refs #31331 -- Checked ONLY_FULL_GROUP_BY mode in ↵Mariusz Felisiak2020-03-031-1/+1
| | | | AggregateTestCase.test_aggregation_subquery_annotation_multivalued().
* Fixed #31150 -- Included subqueries that reference related fields in GROUP ↵Mariusz Felisiak2020-03-031-0/+27
| | | | | | | | | | BY clauses. Thanks Johannes Hoppe for the report. Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Co-authored-by: Simon Charette <charette.s@gmail.com>
* Simplified imports from django.db and django.contrib.gis.db.Nick Pope2020-02-041-3/+2
|
* Fixed #31217 -- Made QuerySet.values()/values_list() group by not selected ↵Mariusz Felisiak2020-02-031-0/+27
| | | | | | | annotations with aggregations used in order_by(). Regression in 59b4e99dd00b9c36d56055b889f96885995e4240. Thanks Jon Dufresne for the report and Simon Charette for the review.
* Refs #31136 -- Made QuerySet.values()/values_list() group only by selected ↵Mariusz Felisiak2020-01-151-0/+25
| | | | | annotation. Regression in 0f843fdd5b9b2f2307148465cd60f4e1b2befbb4.
* Fixed #31136 -- Disabled grouping by aliases on QuerySet.values()/values_list().Mariusz Felisiak2020-01-041-0/+14
| | | | | Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Thanks Sigurd Ljødal for the report.
* Fixed #31109 -- Disabled grouping by aliases on QuerySet.exists().Simon Charette2019-12-231-0/+10
| | | | | | | | | | Clearing the SELECT clause in Query.has_results was orphaning GROUP BY references to it. Thanks Thierry Bastian for the report and Baptiste Mispelon for the bisect. Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80.