[Django] #26792: cache.get_or_set() calculates the default key value in case it is already cached

10 views
Skip to first unread message

Django

unread,
Jun 22, 2016, 2:41:27 PM6/22/16
to django-...@googlegroups.com
#26792: cache.get_or_set() calculates the default key value in case it is already
cached
-------------------------------------+--------------------
Reporter: dvska | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+--------------------
The check "if default is None" causing an unconditional calculation of the
default value.

Behaviour before patch:
{{{
def heavy_routine_whose_result_to_be_cached():
return todays_weather_forecast_calculated

...
cache.set('todays_weather_forecast',
heavy_routine_which_result_to_be_cached())
...
val = cache.get_or_set('todays_weather_forecast',
heavy_routine_which_result_to_be_cached()) ## calculates 2nd time, which
is unwanted behaviour
}}}

Proposed patch -> https://github.com/django/django/pull/6824

--
Ticket URL: <https://code.djangoproject.com/ticket/26792>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 22, 2016, 2:52:11 PM6/22/16
to django-...@googlegroups.com
#26792: cache.get_or_set() calculates the default key value in case it is already
cached
-------------------------------------+-------------------------------------

Reporter: dvska | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by dvska):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> The check "if default is None" causing an unconditional calculation of
> the default value.
>
> Behaviour before patch:
> {{{
> def heavy_routine_whose_result_to_be_cached():
> return todays_weather_forecast_calculated
>
> ...
> cache.set('todays_weather_forecast',
> heavy_routine_which_result_to_be_cached())
> ...
> val = cache.get_or_set('todays_weather_forecast',
> heavy_routine_which_result_to_be_cached()) ## calculates 2nd time, which
> is unwanted behaviour
> }}}
>
> Proposed patch -> https://github.com/django/django/pull/6824

New description:

The check "if default is None" causing an unconditional calculation of the
default value.

Behaviour before patch:
{{{
def heavy_routine_whose_result_to_be_cached():
return todays_weather_forecast_calculated

...
cache.set('todays_weather_forecast',
heavy_routine_whose_result_to_be_cached())


...
val = cache.get_or_set('todays_weather_forecast',
heavy_routine_which_result_to_be_cached()) ## calculates 2nd time, which
is unwanted behaviour
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26792#comment:1>

Django

unread,
Jun 22, 2016, 3:01:04 PM6/22/16
to django-...@googlegroups.com
#26792: cache.get_or_set() calculates the default key value in case it is already
cached
-------------------------------------+-------------------------------------

Reporter: dvska | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by dvska):

* cc: d.v.selitsky@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/26792#comment:2>

Django

unread,
Jul 7, 2016, 4:23:43 PM7/7/16
to django-...@googlegroups.com
#26792: cache.get_or_set() calculates the default key value in case it is already
cached
-------------------------------------+------------------------------------

Reporter: dvska | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/26792#comment:3>

Django

unread,
Jul 11, 2016, 8:18:14 PM7/11/16
to django-...@googlegroups.com
#26792: Allow None for the value of cache.get_or_set()
--------------------------------------+------------------------------------
Reporter: dvska | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Core (Cache system) | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* type: Bug => Cleanup/optimization


--
Ticket URL: <https://code.djangoproject.com/ticket/26792#comment:4>

Django

unread,
Jul 11, 2016, 8:49:52 PM7/11/16
to django-...@googlegroups.com
#26792: Allow None for the value of cache.get_or_set()
--------------------------------------+------------------------------------
Reporter: dvska | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Core (Cache system) | Version: 1.9
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"82be474efa81e5f2e127d711045a2ec06b206a8e" 82be474]:
{{{
#!CommitTicketReference repository=""
revision="82be474efa81e5f2e127d711045a2ec06b206a8e"
Fixed #26792 -- Allowed None for the value of cache.get_or_set().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26792#comment:5>

Reply all
Reply to author
Forward
0 new messages