#29911: Standardize `delete_cached_value API` on model Fields
-------------------------------------+-------------------------------------
     Reporter:  Taylor Hakes         |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Taylor Hakes:

Old 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

New 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

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29911#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/070.5467337c2be28daeb1c7d38907917e46%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to