#27048 closed Cleanup/optimization (fixed)
Document that refresh_from_db() doesn't clear @cached_properties
Reported by: | Jarek Glowacki | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | cached_property refresh_from_db |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Should cached_property
-decorated stuff get wiped when we call .refresh_from_db()
?
I found this related article on the matter.
From a usage perspective, it seems like we wouldn't ever want cached properties to persist through a refresh_from_db()
call, as ideally we'd like to think mymodel.refresh_from_db()
is shorthand synonymous to mymodel = MyModel.objects.get(pk=mymodel.pk)
.
However, from an implementation perspective, maybe this would result in a rabbit hole that tries to pull through other stuff, like #26514.
Basically this ticket picks at:
Note that only fields of the model are reloaded from the database. Other database dependent values such as annotations are not reloaded.`
I have a feeling this might be a conscious design decision, but in case it isn't, thoughts?
Change History (4)
comment:1 by , 8 years ago
Component: | Core (Cache system) → Documentation |
---|---|
Has patch: | set |
Summary: | Clear cached_property on refresh_from_db → Document that refresh_from_db() doesn't clear @cached_properties |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 8 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
refresh_from_db()
doesn't know if a@cached_property
is database-dependent or not. I suppose we can document this: PR.