Opened 6 years ago

Last modified 6 years ago

#29911 closed New feature

Standardize delete_cached_value API on model Fields — at Initial Version

Reported by: Taylor H Owned by: nobody
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I created a custom Django model field that is expensive to calculate and I store a cached value on the model. I am not able to clear the cache when some uses the refresh_from_db() method though, since there is no standard API to hook into it. It appears that there is a custom behavior for ForeignKey that calls the delete_cached_value function, if it detects it's a ForeignKey

https://github.com/django/django/blob/master/django/db/models/base.py#L569

It would be great to allow any custom Field to implement delete_cached_value and have it called inside refresh_from_db. What are your thoughts? I would be happy to submit a PR if this seems reasonable

Change History (0)

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