Code

Opened 3 years ago

Closed 3 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)

fix-cache.base.backends.get_default_key.patch (571 bytes) - added by adsworth 3 years ago.
fix-cache.base.backends.get_default_key-smart_str_on_result.patch (931 bytes) - added by adsworth 3 years ago.

Download all attachments as: .zip

Change History (3)

Changed 3 years ago by adsworth

comment:1 Changed 3 years ago by adsworth

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.