summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
AgeCommit message (Collapse)Author
2023-06-01Fixed #34612 -- Fixed QuerySet.only() crash on reverse relationships.Simon Charette
Regression in b3db6c8dcb5145f7d45eff517bcd96460475c879. Thanks Ian Cubitt for the report. This also corrected test_inheritance_deferred2() test which was previously properly defined and marked as an expected failure but was then wrongly adjusted to mask the lack of support for per-alias deferral that was fixed by #21204.
2023-05-23Fixed #34551 -- Fixed QuerySet.aggregate() crash when referencing subqueries.Simon Charette
Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7. Refs #28477. Thanks Denis Roldán and Mariusz for the test.
2023-05-23Refs #34551 -- Fixed QuerySet.aggregate() crash on precending aggregation ↵Simon Charette
reference. Regression in 1297c0d0d76a708017fe196b61a0ab324df76954. Refs #31679.
2023-05-17Fixed #34570 -- Silenced noop deferral of many-to-many and GFK.Simon Charette
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.
2023-04-24Refs #33766 -- Removed sql.Query.build_filtered_relation_q().Simon Charette
It was a copy of sql.Query._add_q that avoided JOIN updates.
2023-04-24Fixed #33766 -- Resolved FilteredRelation.condition at referencing time.Simon Charette
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.
2023-04-07Fixed #34464 -- Fixed queryset aggregation over group by reference.Simon Charette
Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7. Refs #28477. Thanks Ian Cubitt for the report.
2023-04-05Fixed #34458 -- Fixed QuerySet.defer() crash on attribute names.Simon Charette
Thanks Andrew Cordery for the report. Regression in b3db6c8dcb5145f7d45eff517bcd96460475c879.
2023-04-04Fixed #34450 -- Fixed multi-valued JOIN reuse when filtering by expressions.Simon Charette
Thanks Roman Odaisky for the report.
2023-03-28Refs #29799 -- Added field instance lookups to suggestions in FieldErrors.Mariusz Felisiak
Bug in cd1afd553f9c175ebccfc0f50e72b43b9604bd97.
2023-03-25Fixed #34437 -- Made values() resolving error mention selected annotations.Simon Charette
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.
2023-03-24Fixed #28553 -- Fixed annotation mismatch with ↵David Wobrock
QuerySet.values()/values_list() on compound queries. Co-authored-by: Matthias Kestenholz <mk@feinheit.ch>
2023-03-20Fixed some typos in comments, docstrings, and tests.Liyang Zhang
2023-01-18Refs #34233 -- Used str.removeprefix()/removesuffix().Mariusz Felisiak
2023-01-09Fixed #34176 -- Fixed grouping by ambiguous aliases.Simon Charette
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.
2022-12-01Refs #33308 -- Deprecated support for passing encoded JSON string literals ↵Simon Charette
to JSONField & co. JSON should be provided as literal Python objects an not in their encoded string literal forms.
2022-11-23Fixed #31679 -- Delayed annotating aggregations.Simon Charette
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.
2022-11-14Refs #25307 -- Replaced SQLQuery.rewrite_cols() by replace_expressions().Simon Charette
The latter offers a more generic interface that doesn't require specialized expression types handling.
2022-11-14Reduced nesting inside Query.get_aggregation().Simon Charette
2022-11-14Refs #28477 -- Fixed handling aliased annotations on aggregation.Simon Charette
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.
2022-11-11Refs #28477 -- Reduced complexity of aggregation over qualify queries.Simon Charette
2022-11-09Fixed #28477 -- Stripped unused annotations on aggregation.Simon Charette
Also avoid an unnecessary pushdown when aggregating over a query that doesn't have aggregate annotations.
2022-10-31Used more augmented assignment statements.Nick Pope
Identified using the following command: $ git grep -I '\(\<[_a-zA-Z0-9]\+\>\) *= *\1 *[-+/*^%&|<>@]'
2022-10-06Refs #30158 -- Removed alias argument for Expression.get_group_by_cols().Simon Charette
Recent refactors allowed GROUP BY aliasing allowed for aliasing to be entirely handled by the sql.Query.set_group_by and compiler layers.
2022-10-06Refs #33992 -- Refactored subquery grouping logic.Simon Charette
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.
2022-10-06Refs #33308 -- Enabled explicit GROUP BY and ORDER BY aliases.Simon Charette
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.
2022-10-04Fixed #34012 -- Made QuerySet.order_by() apply transforms on related fields ↵David Sanders
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.
2022-09-22Fixed #34015 -- Allowed filtering by transforms on relation fields.Mariusz Felisiak
2022-09-09Fixed #33975 -- Fixed __in lookup when rhs is a queryset with annotate() and ↵DevilsAutumn
alias(). This fixes clearing selected fields.
2022-08-30Fixed #21204 -- Tracked field deferrals by field instead of models.Simon Charette
This ensures field deferral works properly when a model is involved more than once in the same query with a distinct deferral mask.
2022-07-27Used AND, OR, XOR constants instead of hard-coded values.Nick Pope
2022-07-04Fixed #33816 -- Fixed QuerySet.only() after select_related() crash on proxy ↵Ipakeev
models.
2022-06-27Refs #32786 -- Made query clear ordering when ordered combined queryset is ↵Mariusz Felisiak
used in subquery on Oracle.
2022-05-13Fixed typo in Query.clone()'s docstring.非法操作
2022-04-26Fixed #33655 -- Removed unnecessary constant from GROUP BY clause for ↵marcperrinoptel
QuerySet.exists().
2022-04-12Fixed #24296 -- Made QuerySet.exists() clear selected columns for not sliced ↵mgaligniana
distinct querysets.
2022-04-11Fixed CVE-2022-28347 -- Protected QuerySet.explain(**options) against SQL ↵Mariusz Felisiak
injection on PostgreSQL.
2022-04-11Fixed CVE-2022-28346 -- Protected QuerySet.annotate(), aggregate(), and ↵Mariusz Felisiak
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.
2022-03-31Removed unnecessary Query.get_loaded_field_names_cb() and ↵Mariusz Felisiak
Query.deferred_to_data()'s callback argument.
2022-03-31Refs #24020 -- Removed redundant Query.get_loaded_field_names().Mariusz Felisiak
get_loaded_field_names() is no longer called in multiple places (see 0c7633178fa9410f102e4708cef979b873bccb76) and it's redundant with SQLCompiler.deferred_to_columns().
2022-03-30Fixed #33598 -- Reverted "Removed unnecessary reuse_with_filtered_relation ↵Mariusz Felisiak
argument from Query methods." Thanks lind-marcus for the report. This reverts commit 0c71e0f9cfa714a22297ad31dd5613ee548db379. Regression in 0c71e0f9cfa714a22297ad31dd5613ee548db379.
2022-03-16Refs #30581 -- Allowed sql.Query to be used without model.Gagaro
2022-03-03Refs #27624 -- Optimized Query.clone() a bit.Keryn Knight
2022-03-03Refs #27624 -- Optimized sql.Query creation by moving immutable/singleton ↵Keryn Knight
attributes to class attributes.
2022-02-07Refs #33476 -- Refactored code to strictly match 88 characters line length.Mariusz Felisiak
2022-02-07Refs #33476 -- Reformatted code with Black.django-bot
2022-02-03Refs #33476 -- Refactored problematic code before reformatting by Black.Mariusz Felisiak
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], )
2022-01-17Fixed #29338 -- Allowed using combined queryset in Subquery.Mariusz Felisiak
Thanks Eugene Kovalev for the initial patch, Simon Charette for the review, and Chetan Khanna for help.
2021-12-08Fixed #33319 -- Fixed crash when combining with the | operator querysets ↵Ömer Faruk Abacı
with aliases that conflict.
2021-12-08Refs #33319 -- Added comment about keys/values assertion in ↵Ömer Faruk Abacı
Query.change_aliases().