#19100: @cache_page argument parsing is misleading
-------------------------------------+------------------------------
Reporter: ksamuel | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 1.4
Severity: Normal | Keywords: cache, arguments
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------
Yesterday we moved:
{{{#!python
@cache_page(max_age=60*30)
}}}
Which was working fine. To:
{{{#!python
@cache_page(max_age=60*30, cache="alternative_cache")
}}}
Which triggered the following error:
{{{
The only keyword arguments are cache and key_prefix
}}}
Which is not true since {{{@cache_page(max_age=60*30)}}} worked fine
before.
Of course, after fiddling a bit, we realized that:
{{{#!python
@cache_page(60*30, cache="alternative_cache")
}}}
Worked. And we were a bit confused.
The source code of cache_page shows this:
{{{#!python
def cache_page(*args, **kwargs):
...
cache_alias = kwargs.pop('cache', None)
key_prefix = kwargs.pop('key_prefix', None)
assert not kwargs, "The only keyword arguments are cache and
key_prefix"
}}}
I understand this is for legacy reasons, as I can see the deprecation
warning below these lines:
{{{#!python
def warn():
import warnings
warnings.warn('The cache_page decorator must be called like: '
'cache_page(timeout, [cache=cache name],
[key_prefix=key prefix]). '
'All other ways are deprecated.',
PendingDeprecationWarning,
stacklevel=3)
}}}
But then it should accept max_age as a keyword argument and raise the
deprecation warning OR not accept it at all and have an explicit mandatory
first positional argument being max_age. But not one behavior in one case,
and another in the other case.
--
Ticket URL: <https://code.djangoproject.com/ticket/19100>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.