summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
Commit message (Collapse)AuthorAgeFilesLines
* Fixed #34570 -- Silenced noop deferral of many-to-many and GFK.Simon Charette2023-05-171-1/+9
| | | | | | | | | While deferring many-to-many and GFK has no effect, the previous implementation of QuerySet.defer() ignore them instead of crashing. Regression in b3db6c8dcb5145f7d45eff517bcd96460475c879. Thanks Paco Martínez for the report.
* Refs #33766 -- Removed sql.Query.build_filtered_relation_q().Simon Charette2023-04-241-29/+8
| | | | It was a copy of sql.Query._add_q that avoided JOIN updates.
* Fixed #33766 -- Resolved FilteredRelation.condition at referencing time.Simon Charette2023-04-241-32/+38
| | | | | | | | | | | The previous implementation resolved condition at Join compilation time which required introducing a specialized expression resolving mode to alter the join reuse logic solely during that phase. FilteredRelation.condition is now resolved when the relation is first referenced which maintains the existing behavior while allowing the removal of the specialized resolving mode and address an issue where conditions couldn't spawn new joins.
* Fixed #34464 -- Fixed queryset aggregation over group by reference.Simon Charette2023-04-071-0/+3
| | | | | | | | Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7. Refs #28477. Thanks Ian Cubitt for the report.
* Fixed #34458 -- Fixed QuerySet.defer() crash on attribute names.Simon Charette2023-04-051-1/+2
| | | | | | Thanks Andrew Cordery for the report. Regression in b3db6c8dcb5145f7d45eff517bcd96460475c879.
* Fixed #34450 -- Fixed multi-valued JOIN reuse when filtering by expressions.Simon Charette2023-04-041-1/+1
| | | | Thanks Roman Odaisky for the report.
* Refs #29799 -- Added field instance lookups to suggestions in FieldErrors.Mariusz Felisiak2023-03-281-1/+1
| | | Bug in cd1afd553f9c175ebccfc0f50e72b43b9604bd97.
* Fixed #34437 -- Made values() resolving error mention selected annotations.Simon Charette2023-03-251-5/+10
| | | | | While the add_fields() call from set_values() does trigger validation it does so after annotations are masked resulting in them being excluded from the choices of valid options surfaced through a FieldError.
* Fixed #28553 -- Fixed annotation mismatch with ↵David Wobrock2023-03-241-6/+11
| | | | | | QuerySet.values()/values_list() on compound queries. Co-authored-by: Matthias Kestenholz <mk@feinheit.ch>
* Fixed some typos in comments, docstrings, and tests.Liyang Zhang2023-03-201-1/+1
|
* Refs #34233 -- Used str.removeprefix()/removesuffix().Mariusz Felisiak2023-01-181-2/+1
|
* Fixed #34176 -- Fixed grouping by ambiguous aliases.Simon Charette2023-01-091-30/+15
| | | | | | | | | | | | | | | 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.
* Refs #33308 -- Deprecated support for passing encoded JSON string literals ↵Simon Charette2022-12-011-3/+3
| | | | | | | to JSONField & co. JSON should be provided as literal Python objects an not in their encoded string literal forms.
* Fixed #31679 -- Delayed annotating aggregations.Simon Charette2022-11-231-41/+34
| | | | | | | | | | 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 #25307 -- Replaced SQLQuery.rewrite_cols() by replace_expressions().Simon Charette2022-11-141-62/+25
| | | | | The latter offers a more generic interface that doesn't require specialized expression types handling.
* Reduced nesting inside Query.get_aggregation().Simon Charette2022-11-141-7/+6
|
* Refs #28477 -- Fixed handling aliased annotations on aggregation.Simon Charette2022-11-141-1/+1
| | | | | | | | | | 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.
* Refs #28477 -- Reduced complexity of aggregation over qualify queries.Simon Charette2022-11-111-14/+20
|
* Fixed #28477 -- Stripped unused annotations on aggregation.Simon Charette2022-11-091-20/+51
| | | | | Also avoid an unnecessary pushdown when aggregating over a query that doesn't have aggregate annotations.
* Used more augmented assignment statements.Nick Pope2022-10-311-1/+1
| | | | | | Identified using the following command: $ git grep -I '\(\<[_a-zA-Z0-9]\+\>\) *= *\1 *[-+/*^%&|<>@]'
* Refs #30158 -- Removed alias argument for Expression.get_group_by_cols().Simon Charette2022-10-061-8/+11
| | | | | 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-8/+9
| | | | | | | | | | | 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-2/+15
| | | | | | | 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 #34012 -- Made QuerySet.order_by() apply transforms on related fields ↵David Sanders2022-10-041-0/+1
| | | | | | | | | | | for models with Meta.ordering. This makes QuerySet.order_by() no longer ignore trailing transforms for models with Meta.ordering. As a consequence, FieldError is raised in such cases for non-existent fields. Thanks to Klaas van Schelven for the report and Mariusz Felisiak for the review and advice.
* Fixed #34015 -- Allowed filtering by transforms on relation fields.Mariusz Felisiak2022-09-221-10/+0
|
* Fixed #33975 -- Fixed __in lookup when rhs is a queryset with annotate() and ↵DevilsAutumn2022-09-091-6/+2
| | | | | | alias(). This fixes clearing selected fields.
* Fixed #21204 -- Tracked field deferrals by field instead of models.Simon Charette2022-08-301-90/+63
| | | | | This ensures field deferral works properly when a model is involved more than once in the same query with a distinct deferral mask.
* Used AND, OR, XOR constants instead of hard-coded values.Nick Pope2022-07-271-3/+3
|
* Fixed #33816 -- Fixed QuerySet.only() after select_related() crash on proxy ↵Ipakeev2022-07-041-0/+1
| | | | models.
* Refs #32786 -- Made query clear ordering when ordered combined queryset is ↵Mariusz Felisiak2022-06-271-0/+2
| | | | used in subquery on Oracle.
* Fixed typo in Query.clone()'s docstring.非法操作2022-05-131-1/+1
|
* Fixed #33655 -- Removed unnecessary constant from GROUP BY clause for ↵marcperrinoptel2022-04-261-2/+2
| | | | QuerySet.exists().
* Fixed #24296 -- Made QuerySet.exists() clear selected columns for not sliced ↵mgaligniana2022-04-121-1/+1
| | | | distinct querysets.
* Fixed CVE-2022-28347 -- Protected QuerySet.explain(**options) against SQL ↵Mariusz Felisiak2022-04-111-0/+10
| | | | injection on PostgreSQL.
* Fixed CVE-2022-28346 -- Protected QuerySet.annotate(), aggregate(), and ↵Mariusz Felisiak2022-04-111-0/+14
| | | | | | | | 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.
* Removed unnecessary Query.get_loaded_field_names_cb() and ↵Mariusz Felisiak2022-03-311-12/+5
| | | | Query.deferred_to_data()'s callback argument.
* Refs #24020 -- Removed redundant Query.get_loaded_field_names().Mariusz Felisiak2022-03-311-19/+0
| | | | | | get_loaded_field_names() is no longer called in multiple places (see 0c7633178fa9410f102e4708cef979b873bccb76) and it's redundant with SQLCompiler.deferred_to_columns().
* Fixed #33598 -- Reverted "Removed unnecessary reuse_with_filtered_relation ↵Mariusz Felisiak2022-03-301-9/+38
| | | | | | | | | argument from Query methods." Thanks lind-marcus for the report. This reverts commit 0c71e0f9cfa714a22297ad31dd5613ee548db379. Regression in 0c71e0f9cfa714a22297ad31dd5613ee548db379.
* Refs #30581 -- Allowed sql.Query to be used without model.Gagaro2022-03-161-3/+10
|
* Refs #27624 -- Optimized Query.clone() a bit.Keryn Knight2022-03-031-5/+2
|
* Refs #27624 -- Optimized sql.Query creation by moving immutable/singleton ↵Keryn Knight2022-03-031-60/+63
| | | | attributes to class attributes.
* Refs #33476 -- Refactored code to strictly match 88 characters line length.Mariusz Felisiak2022-02-071-1/+2
|
* Refs #33476 -- Reformatted code with Black.django-bot2022-02-071-228/+388
|
* Refs #33476 -- Refactored problematic code before reformatting by Black.Mariusz Felisiak2022-02-031-4/+4
| | | | | | | | | | | | | | | | | In these cases Black produces unexpected results, e.g. def make_random_password( self, length=10, allowed_chars='abcdefghjkmnpqrstuvwxyz' 'ABCDEFGHJKLMNPQRSTUVWXYZ' '23456789', ): or cursor.execute(""" SELECT ... """, [table name], )
* Fixed #29338 -- Allowed using combined queryset in Subquery.Mariusz Felisiak2022-01-171-0/+6
| | | | Thanks Eugene Kovalev for the initial patch, Simon Charette for the review, and Chetan Khanna for help.
* Fixed #33319 -- Fixed crash when combining with the | operator querysets ↵Ömer Faruk Abacı2021-12-081-8/+17
| | | | with aliases that conflict.
* Refs #33319 -- Added comment about keys/values assertion in ↵Ömer Faruk Abacı2021-12-081-0/+3
| | | | Query.change_aliases().
* Refs #25265 -- Allowed customizing Query's datastructure classes.Erik Cederstrand2021-12-071-7/+14
|
* Fixed #33282 -- Fixed a crash when OR'ing subquery and aggregation lookups.Simon Charette2021-12-021-0/+8
| | | | | | | | 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.
* Refs #24121 -- Added __repr__() to BaseDatabaseWrapper, JoinPromoter, and ↵Jonny Park2021-11-191-0/+6
| | | | SQLCompiler.