summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
AgeCommit message (Collapse)Author
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().
2021-12-07Refs #25265 -- Allowed customizing Query's datastructure classes.Erik Cederstrand
2021-12-02Fixed #33282 -- Fixed a crash when OR'ing subquery and aggregation lookups.Simon Charette
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.
2021-11-19Refs #24121 -- Added __repr__() to BaseDatabaseWrapper, JoinPromoter, and ↵Jonny Park
SQLCompiler.
2021-11-03Fixed #32996 -- Cached PathInfos on relations.Keryn Knight
PathInfo values are ostensibly static over the lifetime of the object for which they're requested, so the data can be memoized, quickly amortising the cost over the process' duration.
2021-10-13Refs #25265 -- Allowed Query subclasses to build filters.Erik Cederstrand
2021-10-06Refs #26430 -- Removed unused branch in sql.Query.get_count().Simon Charette
Now that sql.Query.get_aggregation() properly deals with empty result sets summary Count() annotations cannot result in None. Unused since 9f3cce172f6913c5ac74272fa5fc07f847b4e112.
2021-09-29Fixed #33018 -- Fixed annotations with empty queryset.David Wobrock
Thanks Simon Charette for the review and implementation idea.
2021-09-29Fixed #33141 -- Renamed Expression.empty_aggregate_value to ↵David Wobrock
empty_result_set_value.
2021-09-24Fixed #33124 -- Avoided accessing the database connections when not necessary.Keryn Knight
Follow up to bf5abf1bdcedb15e949db419c61eeec7c88414ea. This also caches the __getitem__ access.
2021-09-20Refs #27624 -- Optimized Query.clone() for non-combined queries.Keryn Knight
This avoids constructing a generator expression and a new tuple if the Query has no combined queries.
2021-09-17Refs #27624 -- Changed Query.explain_info to namedtuple.Adam Johnson
2021-09-17Optimized Query.clone() a bit.Adam Johnson
This removes unnecessary "if ... is None" branches, which are already shallow-copied in the __dict__.copy() call.
2021-09-01Fixed #33073 -- Fixed queryset crash with aggregation and empty/extra ↵David Wobrock
queryset annotation.
2021-08-19Fixed #33025 -- Avoided accessing the database connections in ↵Keryn Knight
Query.build_lookup() when not necessary. Of the built-in backends, only Oracle treats empty strings and nulls as equal, so avoid testing the default connection backend for interprets_empty_strings_as_nulls if it can be established from the lookup that it wouldn't affect the lookup instance returned. This improves performance a small amount for most lookups being built, because accessing the connections requires touching the thread critical `Local` which is an expensive operation.
2021-07-28Refs #32946 -- Changed Query.add_filter() to take two arguments.Keryn Knight
2021-07-22Fixed #32951 -- Removed Query.where_class & co.Nick Pope
Unused since 3caf957ed5eaa831a485abcb89f27266dbf3e82b.
2021-07-20Fixed #32704 -- Fixed list of deferred fields when chaining QuerySet.defer() ↵David Wobrock
after only().
2021-07-20Fixed #32944 -- Avoided unnecessary WhereNode.add() calls.Keryn Knight
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2021-07-15Refs #32508 -- Raised Type/ValueError instead of using "assert" in ↵Daniyal
django.db.models. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2021-07-09Fixed #27021 -- Allowed lookup expressions in annotations, aggregations, and ↵Ian Foote
QuerySet.filter(). Thanks Hannes Ljungberg and Simon Charette for reviews. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2021-07-02Refs #26430 -- Re-introduced empty aggregation optimization.Simon Charette
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.
2021-07-02Fixed #26430 -- Fixed coalesced aggregation of empty result sets.Simon Charette
Disable the EmptyResultSet optimization when performing aggregation as it might interfere with coalescence.
2021-06-30Fixed #32786 -- Moved subquery ordering clearing optimization to the _in lookup.Hannes Ljungberg
Co-Authored-By: Simon Charette <charette.s@gmail.com>
2021-06-30Refs #32786 -- Made Query.clear_ordering() not to cause side effects by default.Hannes Ljungberg
2021-04-28Removed unnecessary reuse_with_filtered_relation argument from Query methods.Nick Pope
In Query.join() the argument reuse_with_filtered_relation was used to determine whether to use == or .equals(). As this area of code is related to aliases, we only expect an instance of Join or BaseTable to be provided - the only two classes that provide .equals(). In both cases, the implementations of __eq__() and equals() are based on use of the "identity" property. __eq__() performs an isinstance() check first, returning NotImplemented if required. BaseTable.equals() then does a straightforward equality check on "identity". Join.equals() is a little bit different as it skips checking the last element of the "identity" property: filtered_relation. This was only included previously when the with_filtered_relation argument was True, impossible since bbf141bcdc31f1324048af9233583a523ac54c94.
2021-04-28Removed unused with_filtered_relation argument from .equals()Nick Pope
Unused since bbf141bcdc31f1324048af9233583a523ac54c94.
2021-04-28Fixed #32632, Fixed #32657 -- Removed flawed support for Subquery ↵Simon Charette
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.
2021-04-21Fixed #32650 -- Fixed handling subquery aliasing on queryset combination.Simon Charette
This issue started manifesting itself when nesting a combined subquery relying on exclude() since 8593e162c9cb63a6c0b06daf045bc1c21eb4d7c1 but sql.Query.combine never properly handled subqueries outer refs in the first place, see QuerySetBitwiseOperationTests.test_subquery_aliases() (refs #27149). Thanks Raffaele Salmaso for the report.
2021-03-10Refs #32508 -- Raised TypeError instead of using "assert" on unsupported ↵Mariusz Felisiak
operations for sliced querysets.
2021-02-24Fixed #32478 -- Included nested columns referenced by subqueries in GROUP BY ↵Simon Charette
on aggregations. Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Refs #31094, #31150. Thanks Igor Pejic for the report.
2021-01-14Refs #7098 -- Removed support for passing raw column aliases to order_by().Mariusz Felisiak
Per deprecation timeline.
2021-01-14Refs #30158 -- Made alias argument required in signature of ↵Mariusz Felisiak
Expression.get_group_by_cols() subclasses. Per deprecation timeline.
2021-01-05Fixed #32231 -- Allowed passing None params to QuerySet.raw().Alexander Lyabah