Changes between Initial Version and Version 1 of Ticket #29911


Ignore:
Timestamp:
Nov 1, 2018, 10:41:24 AM (6 years ago)
Author:
Taylor H
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29911

    • Property Summary Standardize delete_cached_value API on model FieldsStandardize `delete_cached_value API` on model Fields
  • Ticket #29911 – Description

    initial v1  
    1 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
     1I 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`
    22
    33https://github.com/django/django/blob/master/django/db/models/base.py#L569
    44
    5 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
     5It 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
Back to Top