#25591: Cannot QuerySet.update DateRangeField using F() expressions
----------------------------------+------------------------------------
Reporter: synotna | Owner: nobody
Type: New feature | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Simon Charette):
* cc: Claude Paroz (added)
Comment:
A solution to support the assignment of `tuple[Expr, Expr]` here is likely
to have `RangeField` special case the assignment of such objects in its
`get_prep_value`
[https://github.com/django/django/blob/1592f0ac220c1fd37779f6d33efb28ebd60e2e66/django/contrib/postgres/fields/ranges.py#L94-L95
method] by wrapping in in a `Func` as suggested in comment:1 instead of
systematically creating a `range_type(*value)`. This will cover the
following case
{{{#!python
obj.period = (F('date_from'), F('date_to'))
obj.save()
}}}
In order to support the `QuerySet.update` case I don't see a way of doing
it without adapting `UpdateQuery` to
[https://github.com/django/django/blob/6debeac9e7538e0e32883dc36abe6fc40a35c874/django/db/models/sql/subqueries.py#L104-L117
special case] `tuple | list` that contain expressions. Possibly by having
it call `field.get_db_prep_value` which defaults to `get_prep_value` and
would ''engage'' the changes described in the first half of comment.
--
Ticket URL: <https://code.djangoproject.com/ticket/25591#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018d13d53ed8-d3fe942d-12b8-4d98-8128-6965db1d3df4-000000%40eu-central-1.amazonses.com.