summaryrefslogtreecommitdiff
path: root/django/db/models/sql
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.
* Fixed #33759 -- Avoided unnecessary subquery in QuerySet.delete() with ↵4the4ryushin2023-05-011-1/+4
| | | | self-referential subqueries if supported.
* 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.
* Refs #33766 -- Removed unused Join.equals().Simon Charette2023-04-241-7/+0
| | | | | It's unused now that the specialized FilteredRelation.as_sql logic is no more.
* Fixed #33766 -- Resolved FilteredRelation.condition at referencing time.Simon Charette2023-04-242-36/+39
| | | | | | | | | | | 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.
* Refs #16055 -- Deprecated ↵David Wobrock2023-04-181-0/+12
| | | | get_joining_columns()/get_reverse_joining_columns() methods.
* Fixed #16055 -- Fixed crash when filtering against char/text GenericRelation ↵David Wobrock2023-04-181-11/+22
| | | | relation on PostgreSQL.
* 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
|
* Fixed #34368 -- Made subquery raise NotSupportedError when referencing outer ↵Simon Charette2023-02-271-1/+1
| | | | | | | | window expression. Regression in f387d024fc75569d2a4a338bfda76cc2f328f627. Co-authored-by: Jannis Vajen <jvajen@gmail.com>
* Fixed #34372 -- Fixed queryset crash on order by aggregation using OrderBy.Simon Charette2023-02-271-0/+2
| | | | | | Regression in 278881e37619278789942513916acafaa88d26f3 caused by a lack of expression copying when an OrderBy expression is explicitly provided. Thanks Jannis Vajen for the report and regression test.
* Fixed #34346 -- Ordered selected expressions by position.Simon Charette2023-02-201-8/+35
| | | | | | | | | Used the same approach as for #34176 by using selected expressions position to prevent ambiguous aliases in collisions. Thanks henribru for the report. Regression in 04518e310d4552ff7595a34f5a7f93487d78a406.
* Refs #34176 -- Adjusted group by position variables naming to follow SQL spec.Simon Charette2023-02-181-5/+5
| | | | This avoids conceptual collisions with the notion of indices.
* Fixed #34227 -- Fixed QuerySet.select_related() with multi-level ↵朱穆穆2023-01-241-1/+8
| | | | FilteredRelation.
* Fixed #34267 -- Fixed sliced QuerySet.union() crash.Francesco Panico2023-01-201-3/+0
| | | | | | Regression in 3d734c09ff0138441dfe0a59010435871d17950f. Thanks Raphaël Stefanini for the report.
* Refs #34233 -- Used str.removeprefix()/removesuffix().Mariusz Felisiak2023-01-181-2/+1
|
* Fixed #34176 -- Fixed grouping by ambiguous aliases.Simon Charette2023-01-092-45/+39
| | | | | | | | | | | | | | | 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.
* Simplified SQLCompiler.get_group_by() a bit.Simon Charette2023-01-041-4/+2
|
* Fixed #34226 -- Fixed QuerySet.select_related() with multiple ↵朱穆穆2022-12-271-2/+2
| | | | FilteredRelations to the OneToOneField.
* Refs #34226 -- Renamed local field variables in ↵Mariusz Felisiak2022-12-241-12/+16
| | | | SQLCompiler.get_related_selections() to avoid redefinition.
* Refs #33308 -- Deprecated support for passing encoded JSON string literals ↵Simon Charette2022-12-012-12/+6
| | | | | | | 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.
* Fixed #34171 -- Fixed QuerySet.bulk_create() on fields with db_column in ↵DevilsAutumn2022-11-221-2/+2
| | | | | | | | unique_fields/update_fields. Bug in 0f6946495a8ec955b471ca1baaf408ceb53d4796. Thanks Joshua Brooks for the report.
* Fixed #34123 -- Fixed combinator order by alias when using select_related().Simon Charette2022-11-151-10/+20
| | | | | | | | Regression in c58a8acd413ccc992dd30afd98ed900897e1f719. Thanks to Shai Berger for the report and tests. Co-Authored-By: David Sanders <shang.xiao.sanders@gmail.com>
* Avoided unnecessary usage of RawSQL.Simon Charette2022-11-151-4/+4
| | | | This ensures proper alias quoting.
* 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-092-20/+57
| | | | | 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-073-25/+45
| | | | | | 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.
* Refs #17144 -- Removed support for grouping by primary key.Simon Charette2022-11-071-35/+4
| | | | | No core backend require the feature anymore as it was only added to support a MySQL'ism that has been deprecated since then.
* Fixed #31331 -- Switched MySQL to group by selected primary keys.Simon Charette2022-11-071-1/+3
| | | | | | MySQL 5.7.15 supports group by functional dependences so there is no need to special case group by main table primary key anymore and special case the ONLY_FULL_GROUP_BY sql mode.
* Used more augmented assignment statements.Nick Pope2022-10-312-2/+2
| | | | | | Identified using the following command: $ git grep -I '\(\<[_a-zA-Z0-9]\+\>\) *= *\1 *[-+/*^%&|<>@]'
* Fixed #34125 -- Fixed sliced QuerySet.union() crash on a single non-empty ↵Simon Charette2022-10-291-1/+5
| | | | | | | | | queryset. The bug existed since sliced query union was added but was elevated to query union slices by moving the .exists() optimization to the compiler in 3d734c09ff0138441dfe0a59010435871d17950f. Thanks Stefan Hammer for the report.
* Used Query.is_sliced in SQLCompiler.as_sql().Simon Charette2022-10-281-3/+1
|
* Fixed #34105 -- Fixed crash of ordering by nested selected expression.Simon Charette2022-10-181-6/+1
| | | | | | | | This stops ordering by nested selected references. It's not supported on PostgreSQL and not required to support psycopg3. Regression in 04518e310d4552ff7595a34f5a7f93487d78a406. Thanks Matt Westcott for the report.
* Refs #30158 -- Removed alias argument for Expression.get_group_by_cols().Simon Charette2022-10-062-9/+12
| | | | | Recent refactors allowed GROUP BY aliasing allowed for aliasing to be entirely handled by the sql.Query.set_group_by and compiler layers.
* Refs #31150 -- Enabled implicit GROUP BY aliases.Simon Charette2022-10-061-4/+8
| | | | | | | 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-062-10/+16
| | | | | | | | | | | 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-062-7/+33
| | | | | | | 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 #33768 -- Fixed ordering compound queries by nulls_first/nulls_last on ↵Simon Charette2022-10-051-10/+11
| | | | | | | | | | | MySQL. Columns of the left outer most select statement in a combined query can be referenced by alias just like by index. This removes combined query ordering by column index and avoids an unnecessary usage of RawSQL which causes issues for backends that specialize the treatment of null ordering.
* Avoided unnecessary call to .get_source_expressions().Simon Charette2022-10-041-2/+2
| | | | | The SQLCompiler._order_by_pairs() generator method yields instances of OrderBy and not Expression.
* Fixed #34012 -- Made QuerySet.order_by() apply transforms on related fields ↵David Sanders2022-10-042-1/+4
| | | | | | | | | | | 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 #34024 -- Fixed crash when aggregating querysets with Q objects ↵David Sanders2022-09-231-0/+4
| | | | | | | | | | | annotations. This reverts b64db05b9cedd96905d637a2d824cbbf428e40e7. It was reasonable to assume it was unnecessary code as there were no failing tests upon its removal. This commit adds the necessary regression tests for the failing condition identified in #34024 alongside the original tests added in the PR for which WhereNode.is_summary was introduced.