summaryrefslogtreecommitdiff
path: root/django/db/models/expressions.py
Commit message (Collapse)AuthorAgeFilesLines
* Fixed #470 -- Added support for database defaults on fields.Ian Foote2023-05-121-0/+37
| | | | | | | | Special thanks to Hannes Ljungberg for finding multiple implementation gaps. Thanks also to Simon Charette, Adam Johnson, and Mariusz Felisiak for reviews.
* Fixed #34368 -- Made subquery raise NotSupportedError when referencing outer ↵Simon Charette2023-02-271-0/+5
| | | | | | | | window expression. Regression in f387d024fc75569d2a4a338bfda76cc2f328f627. Co-authored-by: Jannis Vajen <jvajen@gmail.com>
* Refs #33476 -- Applied Black's 2023 stable style.David Smith2023-02-011-1/+0
| | | | | | | | Black 23.1.0 is released which, as the first release of the year, introduces the 2023 stable style. This incorporates most of last year's preview style. https://github.com/psf/black/releases/tag/23.1.0
* Fixed #34254 -- Fixed return value of Exists() with empty queryset.Raj Desai2023-01-261-0/+1
| | | | Thanks Simon Charette for reviews.
* Refs #34233 -- Used types.NoneType.Nick Pope2023-01-181-1/+1
| | | Available since Python 3.10 where it was reintroduced.
* Refs #33543 -- Made Expression.asc()/desc() and OrderBy raise ValueError ↵Mariusz Felisiak2023-01-171-12/+1
| | | | | | when nulls_first/nulls_last=False is passed. Per deprecation timeline.
* Fixed #28477 -- Stripped unused annotations on aggregation.Simon Charette2022-11-091-0/+9
| | | | | Also avoid an unnecessary pushdown when aggregating over a query that doesn't have aggregate annotations.
* Refs #33374 -- Adjusted full match condition handling.Simon Charette2022-11-071-10/+7
| | | | | | Adjusting WhereNode.as_sql() to raise an exception when encoutering a full match just like with empty matches ensures that all case are explicitly handled.
* Fixed #16211 -- Added logical NOT support to F expressions.David Wobrock2022-10-311-25/+58
|
* Refs #30158 -- Removed alias argument for Expression.get_group_by_cols().Simon Charette2022-10-061-20/+18
| | | | | Recent refactors allowed GROUP BY aliasing allowed for aliasing to be entirely handled by the sql.Query.set_group_by and compiler layers.
* Refs #33992 -- Refactored subquery grouping logic.Simon Charette2022-10-061-22/+5
| | | | | | | | | | | 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.
* Refs #33308 -- Enabled explicit GROUP BY and ORDER BY aliases.Simon Charette2022-10-061-1/+3
| | | | | | | This ensures explicit grouping from using values() before annotating an aggregate function groups by selected aliases if supported. The GROUP BY feature is disabled on Oracle because it doesn't support it.
* Fixed #33464 -- Resolved output_field for combined numeric expressions with ↵David Wobrock2022-09-271-0/+1
| | | | MOD operator.
* Fixed #33992 -- Fixed queryset crash when aggregating over a group ↵Simon Charette2022-09-081-0/+8
| | | | | | | | | | | | | 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.
* Refs #28333 -- Added partial support for filtering against window functions.Simon Charette2022-08-151-2/+13
| | | | | | | | | | | | | | | | | | | | Adds support for joint predicates against window annotations through subquery wrapping while maintaining errors for disjointed filter attempts. The "qualify" wording was used to refer to predicates against window annotations as it's the name of a specialized Snowflake extension to SQL that is to window functions what HAVING is to aggregates. While not complete the implementation should cover most of the common use cases for filtering against window functions without requiring the complex subquery pushdown and predicate re-aliasing machinery to deal with disjointed predicates against columns, aggregates, and window functions. A complete disjointed filtering implementation should likely be deferred until proper QUALIFY support lands or the ORM gains a proper subquery pushdown interface.
* Replaced Expression.replace_references() with .replace_expressions().Simon Charette2022-08-111-5/+8
| | | | | | | The latter allows for more generic use cases beyond the currently limited ones constraints validation has. Refs #28333, #30581.
* Refs #33895 -- Fixed Case() crash with filters that match everything in ↵Mariusz Felisiak2022-08-101-4/+9
| | | | | When() on Oracle. Follow up to 036bb2b74afb50a71e7a945e8dd83499b603ac3a.
* Fixed #33895 -- Fixed Case() crash with filters that match everything in When().David Wobrock2022-08-091-0/+5
| | | | Thanks shukryzablah for the report.
* Fixed #33902 -- Fixed Meta.constraints validation crash with F() expressions.Mariusz Felisiak2022-08-091-3/+4
| | | | | Thanks Adam Zahradník for the report. Bug in 667105877e6723c6985399803a364848891513cc.
* Fixed #33898 -- Fixed Window() expression crash with ArrayAgg().Mariusz Felisiak2022-08-061-6/+5
| | | | | Thanks Kia for the report. Regression in e06dc4571ea9fd5723c8029959b95808be9f8812.
* Fixed #33543 -- Deprecated passing nulls_first/nulls_last=False to OrderBy ↵Mariusz Felisiak2022-05-121-6/+20
| | | | | and Expression.asc()/desc(). Thanks Allen Jonathan David for the initial patch.
* Fixed #29538 -- Fixed crash of ordering by related fields when Meta.ordering ↵Ed Rivas2022-05-121-0/+12
| | | | | | contains expressions. Thanks Simon Charette for the review.
* Fixed #30581 -- Added support for Meta.constraints validation.Gagaro2022-05-101-0/+12
| | | | Thanks Simon Charette, Keryn Knight, and Mariusz Felisiak for reviews.
* Fixed #33397 -- Corrected resolving output_field for ↵Luke Plant2022-03-311-16/+89
| | | | | | | | | | | | | | | | | | 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 #33397 -- Added register_combinable_fields().Luke Plant2022-03-311-10/+55
|
* Refs #30581 -- Allowed sql.Query to be used without model.Gagaro2022-03-161-6/+9
|
* Fixed #29865 -- Added logical XOR support for Q() and querysets.Ryan Heard2022-03-041-4/+16
|
* Refs #33476 -- Reformatted code with Black.django-bot2022-02-071-186/+318
|
* Refs #33482 -- Fixed QuerySet selecting and filtering againts negated ↵Mariusz Felisiak2022-02-071-1/+4
| | | | | Exists() with empty queryset. Regression in b7d1da5a62fe4141beff2bfea565f7ef0038c94c.
* Fixed #33482 -- Fixed QuerySet filtering againts negated Exists() with empty ↵Simon Charette2022-02-021-7/+12
| | | | | | queryset. Thanks Tobias Bengfort for the report.
* Fixed #33435 -- Fixed invalid SQL generatered by Subquery.as_sql().My-Name-Is-Nabil2022-01-171-1/+2
|
* Fixed #33216 -- Simpilified deconstructed paths for some expressions.Allen Jonathan David2022-01-071-0/+6
|
* Fixed #33282 -- Fixed a crash when OR'ing subquery and aggregation lookups.Simon Charette2021-12-021-4/+5
| | | | | | | | 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 #33304 -- Allowed passing string expressions to Window(order_by).Simon Charette2021-11-231-10/+11
|
* Refs #33304 -- Enclosed aggregate ordering logic in an expression.Simon Charette2021-11-231-2/+22
| | | | | This greatly simplifies the implementation of contrib.postgres' OrderableAggMixin and allows for reuse in Window expressions.
* Fixed #33257 -- Fixed Case() and ExpressionWrapper() with decimal values on ↵Matthijs Kooijman2021-11-081-2/+2
| | | | SQLite.
* Made F deconstruction omit 'expressions' in the path.Adam Johnson2021-10-211-1/+1
|
* Fixed #33018 -- Fixed annotations with empty queryset.David Wobrock2021-09-291-1/+8
| | | | Thanks Simon Charette for the review and implementation idea.
* Fixed #33141 -- Renamed Expression.empty_aggregate_value to ↵David Wobrock2021-09-291-2/+2
| | | | empty_result_set_value.
* Fixed #27021 -- Allowed lookup expressions in annotations, aggregations, and ↵Ian Foote2021-07-091-3/+3
| | | | | | | | QuerySet.filter(). Thanks Hannes Ljungberg and Simon Charette for reviews. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
* Refs #26430 -- Re-introduced empty aggregation optimization.Simon Charette2021-07-021-0/+5
| | | | | | | | | | | | 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.
* Refs #24121 -- Improved Value.__repr__().Mariusz Felisiak2021-05-241-1/+1
|
* Fixed #32714 -- Prevented recreation of migration for Meta.ordering with ↵Simon Charette2021-05-051-2/+1
| | | | | | | | OrderBy expressions. Regression in c8b659430556dca0b2fe27cf2ea0f8290dbafecd. Thanks Kevin Marsh for the report.
* Fixed #32632, Fixed #32657 -- Removed flawed support for Subquery ↵Simon Charette2021-04-281-18/+8
| | | | | | | | | | | | | | | | | | deconstruction. Subquery deconstruction support required implementing complex and expensive equality rules for sql.Query objects for little benefit as the latter cannot themselves be made deconstructible to their reference to model classes. Making Expression @deconstructible and not BaseExpression allows interested parties to conform to the "expression" API even if they are not deconstructible as it's only a requirement for expressions allowed in Model fields and meta options (e.g. constraints, indexes). Thanks Phillip Cutter for the report. This also fixes a performance regression in bbf141bcdc31f1324048af9233583a523ac54c94.
* Refs #25287 -- Added support for multiplying and dividing DurationField by ↵Tobias Bengfort2021-04-201-1/+19
| | | | scalar values on SQLite.
* Removed unnecessary line in OrderBy.as_sql().David Beitey2021-04-201-1/+0
| | | Unnecessary since 7286eaf681d497167cd7dc8b70ceebfcf5cd21ad.
* Fixed #32585 -- Fixed Value() crash with DecimalField on SQLite.Hasan Ramezani2021-03-291-1/+1
|
* Fixed #32478 -- Included nested columns referenced by subqueries in GROUP BY ↵Simon Charette2021-02-241-1/+4
| | | | | | | | | | on aggregations. Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Refs #31094, #31150. Thanks Igor Pejic for the report.
* Fixed #26167 -- Added support for functional indexes.Hannes Ljungberg2021-01-131-1/+8
| | | | | | Thanks Simon Charette, Mads Jensen, and Mariusz Felisiak for reviews. Co-authored-by: Markus Holtermann <info@markusholtermann.eu>
* Fixed #32200 -- Fixed grouping by ExpressionWrapper() with Q objects.Hasan Ramezani2020-11-191-3/+7
| | | | | | Thanks Gordon Wrigley for the report. Regression in df32fd42b84cc6dbba173201f244491b0d154a63.