Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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 Tim Graham, 8 years ago

Component: Core (Cache system)Documentation
Has patch: set
Summary: Clear cached_property on refresh_from_dbDocument that refresh_from_db() doesn't clear @cached_properties
Triage Stage: UnreviewedAccepted

refresh_from_db() doesn't know if a @cached_property is database-dependent or not. I suppose we can document this: PR.

comment:2 by Claude Paroz, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:3 by GitHub <noreply@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 95560054:

Fixed #27048 -- Documented that refresh_from_db() doesn't reload @cached_properties.

comment:4 by Tim Graham <timograham@…>, 8 years ago

In eea74ed:

[1.10.x] Fixed #27048 -- Documented that refresh_from_db() doesn't reload @cached_properties.

Backport of 9556005425ca3d1c8c2a0e8b48e228e63a0bdd32 from master

Note: See TracTickets for help on using tickets.
Back to Top