#26916: Prefetch's to_attr does not write into cached_properties in 1.10
-------------------------------------+-------------------------------------
Reporter: karyon | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Release blocker | 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 charettes):
* severity: Normal => Release blocker
* cc: charettes (added)
* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* needs_docs: => 0
* stage: Unreviewed => Accepted
Comment:
The underlying issue is how the prefetch related algorithm for the
`to_attr` case detects whether or not a relationship is already fetched by
using `hasattr(instance, to_attr)` on the first object of the returned
queryset.
In the reported case the target attribute is a `cached_property` which
makes the detection fail as `hasattr(instance, to_attr)` returns `True`
even if relationship is not fetched yet.
Ideally the recursive algorithm should pass around its prefetching state
between steps instead of relying on attribute and key (when the related
manager is used directly) existence but I suspect this would be too
invasive to backport to 1.10 at this point.
Instead I suggest special casing the `is_fetched` detection for the
`cache_property` case by looking of `to_attr in instance.__dict__` if
`getattr(instance.__class__, to_attr, None)` is an instance of
`cached_property`.
The state passing refactor could be handled in another ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/26916#comment:1>
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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.b284a0684c178d4d19d47c8006c511ad%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.