Opened 8 years ago

Closed 8 years ago

#26462 closed Bug (fixed)

UnicodeEncodeError when warning about too long caching keys on Python 2

Reported by: Przemysław Suliga Owned by: nobody
Component: Core (Cache system) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

On Python 2 warnings.warn() expects a message that can be coerced to a str.

Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import warnings
>>> warnings.warn(u'清')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/warnings.py", line 33, in _show_warning
    file.write(formatwarning(message, category, filename, lineno, line))
  File "/usr/lib/python2.7/warnings.py", line 42, in formatwarning
    s =  "%s:%s: %s: %s\n" % (filename, lineno, category.__name__, message)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u6e05' in position 0: ordinal not in range(128)

BaseCache.validate_key() fails to create a proper `message` by using "%s" to interpolate the key into the message instead of using "%r".

Change History (3)

comment:1 by Przemysław Suliga, 8 years ago

Component: UncategorizedCore (Cache system)

comment:2 by Simon Charette, 8 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug
Version: 1.9master

comment:3 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 90ce5d46:

Fixed #26462 -- Fixed Python 2 UnicodeEncodeError when warning about long cache keys.

Note: See TracTickets for help on using tickets.
Back to Top