#20241: QuerySets with callable filter args have said args evaluated only once
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
christopher.m.pike@… | Status: new
Type: Bug | Version: 1.5
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Comment (by akaariai):
The reasons why fixing this isn't easy:
1. The WhereNode._prepare_data() call is done at .filter() call time.
The _prepare_data() method does some transformations based on the type of
the value, specifically datetime.datetime values will cause some
transformations. If the callable is timezone.now, then the lookup will not
work correctly.
2. The value will need to be resolved for isnull lookups (isnull=True
lookups will need to produce LEFT OUTER JOINs and join promotion is done
at .filter() call time).
3. Some advanced constructs do not work correctly - returning F()
objects for example (they don't work correctly even now).
At least no.1 will need to be fixed if the value resolving is deferred to
query execution time. So, _prepare_data will need to be moved to query
execution time. The only problematic case seems to be iterators - they
must not be consumed multiple times, and this would happen if all of
_prepare_data is moved to query execution time.
Fixing number 2 and 3 properly will be really hard (need to alter the join
types at execution time, and that is problematic for multiple reasons, not
least because the query should not be altered at execution time...). But,
I am not sure if those need to be fixed at all, they could be documented
as known limitations when using callable arguments. In practice the
limitations wouldn't cause much trouble to users, and it is easy enough to
raise errors in problematic cases.
--
Ticket URL: <https://code.djangoproject.com/ticket/20241#comment:4>
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 post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.