#30278: Using del on uncalled cached_property throws exception.
-----------------------------------+--------------------------------------
Reporter: Matthew Schinckel | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: cached_property | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Comment (by Curtis Maloney):
The problem here is (a) fundamental to how Python works, and (b)
complicated by `cached_property` "cheating".
So, `cached_property` works by saving the value it calculates into the
instances `__dict__`.
This means next time that attribute is accessed, _Python_ will check
`__dict__` first, and not even try the property.
Calling `del` will remove the entry from the instances `__dict__`.
However, if it's not there, it will fall back to the class's property.
This causes the attribute error, because the property class does not have
a `__delete__` method.
If it did have a `__delete__` method, Python's lookup would differ, and it
would _not_ check `__dict__` before calling the property. (the official
documentation mentions this about `__get__`, but a simple test shows it
applies to `__delete__` equally)
https://docs.python.org/3/reference/datamodel.html#invoking-descriptors
So, we can't have _both_ - if we support del on uninvoked
`cached_property` we lose the utility of `cached_property` (or, at least,
the performance)
--
Ticket URL: <https://code.djangoproject.com/ticket/30278#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/067.1d8245e3f12be2e5da758e72a16147c1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.