Opened 14 years ago
Closed 14 years ago
#16993 closed Bug (invalid)
In core.cache.backends.BaseCache.default_key_func join expects character string
| Reported by: | adsworth | Owned by: | adsworth |
|---|---|---|---|
| Component: | Python 3 | Version: | 1.3 |
| Severity: | Normal | Keywords: | |
| Cc: | adsworth | Triage Stage: | Unreviewed |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The join in [[source:django/trunk/django/core/cache/backends/base.py#L26|core.cache.backends.BaseCache.default_key_func]] expects a character string instead of a byte string. key_prefix is encoded to a byte string in BaseCache.__init__ and key is encoded directly in default_key_func.
The simple solution is wrapping key_prefix and key with str() for which a patch is attached. fix-cache.base.backends.get_default_key.patch
This feels backwards though, but I'm not sure about the best solution. How about calling smart_str on the result of the join and getting rid of the smart_str on key_prefix and key? For this solution I also attached a patch. This patch also works fine in py2.X if the key_prefix is a unicode string that contains ÖÄÜ^. fix-cache.base.backends.get_default_key-smart_str_on_result.patch
Attachments (2)
Change History (3)
by , 14 years ago
| Attachment: | fix-cache.base.backends.get_default_key.patch added |
|---|
by , 14 years ago
| Attachment: | fix-cache.base.backends.get_default_key-smart_str_on_result.patch added |
|---|
comment:1 by , 14 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
I'm closing this in favor of #16997 which corrects contrib.sessions for Python3.
The patch there only implements the the second solution of this ticket,. Which IMHO is the better solution.