Skip to content

Commit

Permalink
fix: Connection.encode complains when value is an object having unico…
Browse files Browse the repository at this point in the history
…de characters in its printable representation
  • Loading branch information
Eric Du committed May 4, 2015
1 parent bc61eb9 commit 19d48d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def encode(self, value):
elif isinstance(value, float):
value = b(repr(value))
elif not isinstance(value, basestring):
value = str(value)
value = unicode(value)
if isinstance(value, unicode):
value = value.encode(self.encoding, self.encoding_errors)
return value
Expand Down
7 changes: 7 additions & 0 deletions tests/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def test_list_encoding(self, r):
r.rpush('a', *result)
assert r.lrange('a', 0, -1) == result

def test_object_value(self, r):
unicode_string = unichr(3456) + u('abcd') + unichr(3421)
r['unicode-string'] = Exception(unicode_string)
cached_val = r['unicode-string']
assert isinstance(cached_val, unicode)
assert unicode_string == cached_val


class TestCommandsAndTokensArentEncoded(object):
@pytest.fixture()
Expand Down

0 comments on commit 19d48d8

Please sign in to comment.