Re: [Django] #29911: Standardize delete_cached_value API on model Fields (was: Standardize `delete_cached_value API` on model Fields)

2018-11-01 Thread Django
#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
-+-

-- 
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.f1e301467c1bcf5d3a90b23c3de9b7dd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29911: Standardize `delete_cached_value API` on model Fields (was: Standardize delete_cached_value API on model Fields)

2018-11-01 Thread Django
#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: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
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.