summaryrefslogtreecommitdiff
path: root/django/db/models/lookups.py
AgeCommit message (Collapse)Author
2026-03-09Refactored PatternLookup to improve readability.Tim Graham
2026-03-08Added DatabaseFeatures.pattern_lookup_needs_param_pattern.Tim Graham
It's useful on MongoDB.
2025-12-22Fixed #36787 -- Fixed crash in In lookups with mixed expressions and strings.JaeHyuck Sa
Signed-off-by: JaeHyuck Sa <wogur981208@gmail.com>
2025-12-10Refs #36025 -- Made get_prep_lookup() pass output_field when wrapping direct ↵Clifford Gama
values in Value. Previously, only strings were supplied with an output_field when wrapping direct value iterable elements in Value expressions for ExpressionList. This caused problems for __in lookups on JSONField when using expressions alongside direct values, as JSONField values can have different types which need to be adapted by the field's get_db_prep_value(). Refs #36689. Thanks Jacob Walls for the review.
2025-10-29Refs #35972 -- Returned params in a tuple in further lookups.Jacob Walls
2025-08-04Fixed #35972 -- Fixed lookup crashes after subquery annotations.Jacob Walls
2025-02-11Fixed #36149 -- Allowed subquery values against tuple exact and in lookups.Simon Charette
Non-tuple exact and in lookups have specialized logic for subqueries that can be adapted to properly assign select mask if unspecified and ensure the number of involved members are matching on both side of the operator.
2025-02-06Refs #34975 -- Removed unnecessary lookups.In.get_refs().Simon Charette
Now that In.get_source_expression() includes its right-hand-side when it contains expressions (refs #36025) it no longer requires a specialized get_refs() method.
2025-02-06Fixed #36025 -- Fixed re-aliasing of iterable (in/range) lookups rhs.Simon Charette
In order for Expression.relabeled_clone to work appropriately its get_source_expressions method must return all resolvable which wasn't the case for Lookup when its right-hand-side is "direct" (not a compilable). While refs #22288 added support for non-literals iterable right-hand-side lookups it predated the subclassing of Lookup(Expression) refs #27021 which could have been an opportunity to ensure right-hand-sides are always resolvable (ValueList and ExpressionList). Addressing all edge case with non-resolvable right-hand-sides would require a significant refactor and deprecation of some parts of the Lookup interface so this patch only focuses on FieldGetDbPrepValueIterableMixin (In and Range lookups) by making sure that a right-hand-side containing resolvables are dealt with appropriately during the resolving phase. Thanks Aashay Amballi for the report.
2025-01-15Refs #34547 -- Removed DatabaseOperations.field_cast_sql() per deprecation ↵Sarah Boyce
timeline.
2025-01-07Fixed #36042 -- Raised ValueError when using CompositePrimaryKey as rhs.Jacob Walls
2024-09-11Fixed #35752 -- Fixed crash when using In() lookup in filters.Bendeguz Csirmaz
2024-03-13Refs #32673, Refs #35295 -- Avoided wrapping rhs direct values in lookups.Mariusz Felisiak
2024-01-26Applied Black's 2024 stable style.Mariusz Felisiak
https://github.com/psf/black/releases/tag/24.1.0
2024-01-16Fixed #35111 -- Fixed compilation of DateField __in/__range rhs on SQLite ↵Simon Charette
and MySQL. Also removed tests that ensured that adapt_(date)timefield backend operations where able to deal with expressions when it's not the case for any other adapt methods.
2023-11-18Refs #34975 -- Complemented rhs filtering aggregations for __in lookup.Simon Charette
While this isn't a regression it's clear that similar logic should be applied when dealing with lists of expressions passed as a lookup value.
2023-09-22Fixed #34840 -- Avoided casting string base fields on PostgreSQL.Mariusz Felisiak
Thanks Alex Vandiver for the report. Regression in 09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca.
2023-08-31Fixed #34547 -- Deprecated DatabaseOperations.field_cast_sql().David Smith
2023-08-04Fixed #34754 -- Fixed JSONField check constraints validation on NULL values.Simon Charette
The __isnull lookup of JSONField must special case Value(None, JSONField()) left-hand-side in order to be coherent with its convoluted null handling. Since psycopg>=3 offers no way to pass a NULL::jsonb the issue is resolved by optimizing IsNull(Value(None), True | False) to True | False. Regression in 5c23d9f0c32f166c81ecb6f3f01d5077a6084318. Thanks Alexandre Collet for the report.
2023-05-12Fixed #470 -- Added support for database defaults on fields.Ian Foote
Special thanks to Hannes Ljungberg for finding multiple implementation gaps. Thanks also to Simon Charette, Adam Johnson, and Mariusz Felisiak for reviews.
2023-03-09Fixed #27397 -- Prevented integer overflows on integer field lookups.Simon Charette
This prevents a sqlite3 crash and address a potential DDoS vector on PostgreSQL caused by full-table-scans on overflows.
2022-12-15Fixed #33308 -- Added support for psycopg version 3.Daniele Varrazzo
Thanks Simon Charette, Tim Graham, and Adam Johnson for reviews. Co-authored-by: Florian Apolloner <florian@apolloner.eu> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2022-11-15Refs #33308 -- Stopped inheriting from FieldGetDbPrepValueMixin by ↵Simon Charette
PostgresOperatorLookup.
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-05-19Fixed #33705 -- Fixed crash when using IsNull() lookup in filters.David Wobrock
Thanks Florian Apolloner for the report. Thanks Simon Charette for the review.
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], )
2021-12-02Refs #32690 -- Altered lookups Query rhs alterations during initialization.Simon Charette
Having it happen at the lookup creation time ensures entry points called before the compilation phase (e.g. get_group_by_cols) don't have to duplicate the logic in charge of altering Query instances used as rhs. It also has the nice effect of reducing the amount of time the alteration logic to once as opposed to multiple times if the queryset is compiled more than once.
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-06-30Fixed #32786 -- Moved subquery ordering clearing optimization to the _in lookup.Hannes Ljungberg
Co-Authored-By: Simon Charette <charette.s@gmail.com>
2021-05-24Refs #24121 -- Added __repr__() to Lookup.saeedblanchette
2021-05-05Fixed #32690 -- Fixed __in lookup crash when combining with filtered aggregates.Simon Charette
Having lookups group by subquery right-hand-sides is likely unnecessary in the first place but relatively large amount of work would be needed to achieve that such as making Lookup instances proper resolvable expressions. Regression in 35431298226165986ad07e91f9d3aca721ff38ec. Thanks James A. Munsch for the report.
2021-04-23Refs #32673 -- Fixed lookups crash when comparing against lookups on Oracle.Mariusz Felisiak
Follow up to 170b006ce82b0ecf26dc088f832538b747ca0115.
2021-04-23Fixed #32673 -- Fixed lookups crash when comparing against lookups on ↵Simon Charette
PostgreSQL. Regression in 3a505c70e7b228bf1212c067a8f38271ca86ce09. Nonlitteral right-hand-sides of lookups need to be wrapped in parentheses to avoid operator precedence ambiguities. Thanks Charles Lirsac for the detailed report.
2021-03-23Fixed #32573 -- Fixed bounds in __iso_year lookup optimization.Florian Demmer
2021-01-14Refs #30841 -- Made isnull lookup raise ValueError for non-boolean values.Mariusz Felisiak
Per deprecation timeline.
2020-10-28Refs #27149 -- Fixed sql.Query identity.Simon Charette
By making Query subclass BaseExpression in 35431298226165986ad07e91f9d3aca721ff38ec the former defined it's identity based off _construct_args which is not appropriate.
2020-10-14Refs #32096 -- Fixed __in lookup crash against key transforms for JSONField.Mariusz Felisiak
Regression in 6789ded0a6ab797f0dcdfa6ad5d1cfa46e23abcd and 1251772cb83aa4106f526fe00738e51c0eb59122. Thanks Simon Charette and Igor Jerosimić for the report.
2020-07-30Bumped minimum isort version to 5.1.0.David Smith
Fixed inner imports per isort 5. isort 5.0.0 to 5.1.0 was unstable.
2020-07-15Fixed #30446 -- Resolved Value.output_field for stdlib types.Simon Charette
This required implementing a limited form of dynamic dispatch to combine expressions with numerical output. Refs #26355 should eventually provide a better interface for that.
2020-06-11Fixed #31667 -- Made __in lookup ignore None values.Adam Johnson
2020-04-01Refs #12990 -- Moved PostgresSimpleLookup to the ↵Mariusz Felisiak
django.db.models.lookups.PostgresOperatorLookup.
2019-11-21Refs #25367 -- Moved conditional expression wrapping to the Exact lookup.Simon Charette
2019-10-21Fixed #30841 -- Deprecated using non-boolean values for isnull lookup.André Ericson
2019-09-23Fixed #29915 -- Added support for values with hyphens to pattern lookups for ↵Ian Foote
UUIDField on backends without UUID datatype. Support hyphens in iexact, contains, icontains, startswith, istartswith, endswith and iendswith UUIDField filters on backends without UUID datatype.
2019-09-20Fixed #30771 -- Fixed exact lookup against queries with selected columns.James Timmins
Use pre-existing select fields (and thereby GROUP BY fields) from subquery if they were specified, instead of always defaulting to pk. Thanks Aur Saraf for the report and Simon Charette for guidance.
2019-08-29Refs #25367 -- Simplified OrderBy and Lookup by using Case() instead of ↵Mariusz Felisiak
RawSQL() on Oracle. Follow up to efa1908f662c19038a944129c81462485c4a9fe8.
2019-08-13Refs #25367 -- Moved Oracle Exists() handling to contextual methods.Simon Charette
Oracle requires the EXISTS expression to be wrapped in a CASE WHEN in the following cases. 1. When part of a SELECT clause. 2. When part of a ORDER BY clause. 3. When compared against another expression in the WHERE clause. This commit moves the systematic CASE WHEN wrapping of Exists.as_oracle to contextual .select_format, Lookup.as_oracle, and OrderBy.as_oracle methods in order to avoid unnecessary wrapping.
2019-06-25Fixed #30477 -- Made reverse lookup use Field.get_db_prep_value() from the ↵can
target field.
2019-05-21Refs #29396, #30494 -- Reduced code duplication in year lookups.Simon Charette