| Age | Commit message (Collapse) | Author |
|
Applying a transform to an annotation alias in values() crashed with
AttributeError when the annotation's output_field was not attached to a
model:
Book.objects.annotate(published=TruncMonth("pubdate")).values("published__year")
AttributeError: 'DateField' object has no attribute 'model'
Thanks David Smith for offering a useful test case during triage.
Co-authored-by: ontowhee <82607723+ontowhee@users.noreply.github.com>
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
|
|
JoinPromoter didn't handle XOR conditions. Because of this, a negated
XOR could use an INNER JOIN and remove rows that should be returned.
Thanks Simon Charette and Sarah Boyce for review.
|
|
functools.cached_property.
Since Python 3.12, `functools.cached_property` no longer takes a lock
(https://github.com/python/cpython/issues/87634), which was the main
objection to using it instead of Django's own implementation.
`Prefetch(to_attr=...)` and the admindocs model detail page now accept
`functools.cached_property` as well as Django's own `cached_property`.
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
|
|
Reorganizing its logic to branch of `lookup_type` at an earlier layer should
simplify its upcoming adjustment to adequately handle __in=[None] lookups and
should make it easier to reason about eventually replacing it by Expression
flags and methods refs #24267.
|
|
Made Query.get_names_to_join() preserve annotation aliases and used it
in SQLCompiler.get_distinct() instead of splitting on LOOKUP_SEP.
Thanks Jacob Walls for the report and the suggested approach, and
Annabelle Wiegart for the groundwork in #36945.
|
|
Updated references to RemovedInDjango70Warning to use the new warning,
and adjusted references to "Django 7.0" to "Django 2028".
RemovedInDjango70Warning remains importable as an alias of the same
class, so existing warning filters and except clauses in third-party
code keep working across the rename.
|
|
When two lookup paths resolve to the same column, values() selects that
column once per path, at a different position each time. get_distinct()
refers to such selections by expression, and PostgreSQL binds an
expression reference to the first position the expression is selected
at. Ordering referred to each selection by its own position, so the
later ones yielded sort keys that DISTINCT ON could not be matched
against:
SELECT DISTINCT ON expressions must match initial ORDER BY
expressions
Ordering now refers to the first position an expression is selected at
when distinct fields are used. Annotations take part in that, as
PostgreSQL binds to their position as well when they select an
expression first, but their alias keeps referring to their own position
since get_distinct() refers to annotations by alias. Raw selections are
left out as equal SQL is not necessarily interchangeable, e.g. two
volatile extra() selections must keep ordering by their own position.
Regression in 65ad4ade74dc9208b9d686a451cd6045df0c9c3a.
Thanks Robert Leach for the report and Simon Charette for the review.
|
|
aliases correctly.
Made Query.add_fields(), Query.add_ordering() and
SQLCompiler.find_ordering_name() look up FilteredRelation aliases
before splitting field names to relationship traversals. Added
.test_alias_values() and .test_alias_order_by() to
FilteredRelationTests.
Thanks Pravin Kamble for the review.
|
|
|
|
Thanks to these people for pointing these out:
* Hojeong Park
* Natalia Bidart
* Sulav Raj Bista
|
|
|
|
on Oracle.
Thanks Simon Charette, JaeHyuck Sa, and Shai Berger for reviews.
|
|
compound queries on SQLite."
This mostly reverts 2314cdf1ff860058a6579bb9f9bac1253fc9ab43,
but keeps the removal of some test skips.
|
|
queries also.
Thanks Shai Berger for the report.
Regression in 087bb9e8f3478d53f12b1737af865992af17c5f2.
(That commit drove more traffic into an error that would have been
reachable only with an explicit order_by() after each union().)
Co-authored-by: Simon Charette <charettes@gmail.com>
Co-authored-by: siddus <dcsid10@gmail.com>
|
|
|
|
|
|
and random order_by strings.
Run this example:
```python
User.objects.values("is_staff").annotate(latest=Max("date_joined")).order_by("-latest").count()
```
You should see the following exception:
```
django.core.exceptions.FieldError: Cannot resolve keyword '-latest' into field.
```
Regression in 2ce5cb0f7a4618dfdc5f5c10e53e2e9b9543d298.
|
|
Thanks Simon Charette and Tim Graham for reviews, and Jason Hall for a
prior iteration.
|
|
It has been superseded with .quote_name(), which ensures aliases are
always quoted.
|
|
This ensures all database identifiers are quoted independently of their orign
and most importantly that user provided aliases through annotate() and alias()
which paves the way for dropping the allow list of characters such aliases can
contain.
This will require adjustments to raw SQL interfaces such as RawSQL that might
make reference to ORM managed annotations as these will now be quoted.
The `SQLCompiler.quote_name_unless_alias` method is kept for now as an alias
for the newly introduced `.quote_name` method but will be duly deprecated in
a follow up commit.
|
|
get_placeholder_sql.
The lack of ability of the get_placeholder call chain to return SQL and
parameters separated so they can be mogrified by the backend at execution time
forced implementations to dangerously interpolate potentially user controlled
values.
The get_placeholder_sql name was chosen due to its proximity to the previous
method, but other options such as Field.as_sql were considered but ultimately
rejected due to its different input signature compared to Expression.as_sql
that might have lead to confusion.
There is a lot of overlap between what Field.get_db_prep_value and
get_placeholder_sql do but folding the latter in the former would require
changing its return signature to return expression which is a way more invasive
change than what is proposed here.
Given we always call get_db_prep_value it might still be an avenue worth
exploring in the future to offer a publicly documented interface to allow field
to take an active part in the compilation chain.
Thanks Jacob for the review.
|
|
contain periods.
This prevents failures at the database layer, given that aliases in the
ON clause are not quoted.
Systematically quoting aliases even in FilteredRelation is tracked in
https://code.djangoproject.com/ticket/36795.
|
|
with periods.
Before, `order_by()` treated a period in a field name as a sign that it
was requested via `.extra(order_by=...)` and thus should be passed
through as raw table and column names, even if `extra()` was not used.
Since periods are permitted in aliases, this meant user-controlled
aliases could force the `order_by()` clause to resolve to a raw table
and column pair instead of the actual target field for the alias.
In practice, only `FilteredRelation` was affected, as the other
expressions we tested, e.g. `F`, aggressively optimize away the ordering
expressions into ordinal positions, e.g. ORDER BY 2, instead of ORDER BY
"table".column.
Thanks Solomon Kebede for the report, and Simon Charette and Jake Howard
for reviews.
|
|
control characters.
Control characters in FilteredRelation column aliases could be used for
SQL injection attacks. This affected QuerySet.annotate(), aggregate(),
extra(), values(), values_list(), and alias() when using dictionary
expansion with **kwargs.
Thanks Solomon Kebede for the report, and Simon Charette, Jacob Walls,
and Natalia Bidart for reviews.
|
|
values()/values_list() calls.
Signed-off-by: JaeHyuck Sa <wogur981208@gmail.com>
|
|
Signed-off-by: JaeHyuck Sa <wogur981208@gmail.com>
|
|
Thanks Adam Sołtysik for the implementation idea.
|
|
already-closed cursor.
|
|
explicit grouping.
Co-authored-by: Simon Charette <charette.s@gmail.com>
|
|
This is also applicable on CockroachDB.
|
|
|
|
missing from explicit grouping."
This reverts commit ea3a71c2d09f8281d8a50ed20e40e1fb13db5cd9.
The implementation was flawed, as self.group_by contains Cols, not aliases.
|
|
explicit grouping.
Co-authored-by: Simon Charette <charette.s@gmail.com>
|
|
|
|
and extra() against SQL injection in column aliases on MySQL/MariaDB.
Thanks sw0rd1ight for the report.
Follow up to 93cae5cb2f9a4ef1514cf1a41f714fef08005200.
|
|
ManyToManyField was already excluded from fields, concrete_fields,
and local_concrete_fields in Options.
|
|
Follow-up to cb13792938f2c887134eb6b5164d89f8d8f9f1bd. Refs #34437.
|
|
Follow-up to 8ede411a81b40ca53362e6788601193c7e56a0cf.
|
|
via ForeignObject.
|
|
This required implementing UPDATE RETURNING machinery that heavily
borrows from the INSERT one.
|
|
FieldError is now emitted for invalid update calls involving reverse
relations, where previously they failed with AttributeError.
|
|
column aliases.
Thanks Eyal Gabay (EyalSec) for the report.
|
|
values()/values_list().
Thanks Jacob Walls and Simon Charette for tests.
Signed-off-by: SaJH <wogur981208@gmail.com>
|
|
values().
|
|
Renamed existing methods and abstractions used for INSERT … RETURNING
to be generic enough to be used in the context of UPDATEs as well.
This also consolidates SQL compliant implementations on
BaseDatabaseOperations.
|
|
against composite pks.
Follow-up to 8561100425876bde3be4b2a22324655f74ff9609.
Co-authored-by: Simon Charette <charette.s@gmail.com>
|
|
Manually reformatted some comments and docstrings where autofix_w505.py
changed the meaning of the formatting.
|
|
Rewrapped long docstrings and block comments to 79 characters + newline
using script from https://github.com/medmunds/autofix-w505.
|
|
Unintentional support existed only on SQLite and Oracle.
|
|
|