{{{#!python
key = self.make_key(key, version=version)
self.validate_key(key)
}}}
We can define a helper function on the base cache backend that can be used
to avoid repetitiveness and help ensure that we consistently call
`.validate_key()` after `.make_key()`:
{{{#!python
def make_and_validate_key(self, key, version=None):
key = self.make_key(key, version=version)
self.validate_key(key)
return key
}}}
An alternative proposal is to have `.make_key()` learn a `validate` flag,
but we'd probably need to have it as `False` by default for backward
compatibility and we'd may still have issues if users have overridden
`.make_key()`. So it would require documentation changes, release notes,
and a deprecation period.
--
Ticket URL: <https://code.djangoproject.com/ticket/33060>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/14802 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/33060#comment:1>
* stage: Unreviewed => Accepted
Comment:
Adding `make_and_validate_key()` sounds reasonable.
--
Ticket URL: <https://code.djangoproject.com/ticket/33060#comment:2>
* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/33060#comment:3>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"68b8eda78864b78d1b8b2529ec119ec440f8458a" 68b8eda7]:
{{{
#!CommitTicketReference repository=""
revision="68b8eda78864b78d1b8b2529ec119ec440f8458a"
Refs #33060 -- Added .make_key() in .touch() for dummy cache backend.
All cache operations should use make_key().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33060#comment:4>
* needs_better_patch: 1 => 0
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33060#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"ec2f6ea9c6203524933e08d069733cd00a09ede3" ec2f6ea9]:
{{{
#!CommitTicketReference repository=""
revision="ec2f6ea9c6203524933e08d069733cd00a09ede3"
Refs #33060 -- Added memcached test for make_key() making keys invalid.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33060#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"42dfa97e191d8f7ffdc0b5d9502949ef3b8ef356" 42dfa97e]:
{{{
#!CommitTicketReference repository=""
revision="42dfa97e191d8f7ffdc0b5d9502949ef3b8ef356"
Fixed #33060 -- Added BaseCache.make_and_validate_key() hook.
This helper function reduces the amount of duplicated code and makes it
easier to ensure that we always validate the keys.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33060#comment:8>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"4b82578a6045746e7c470b7881dfcf182fd57048" 4b82578a]:
{{{
#!CommitTicketReference repository=""
revision="4b82578a6045746e7c470b7881dfcf182fd57048"
Refs #33060 -- Ensured cache backends validate keys.
The validate_key() function should be called after make_key() to ensure
that the validation is performed on the key that will actually be
stored in the cache.
Co-authored-by: Mariusz Felisiak <felisiak...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33060#comment:7>