Skip to content

Commit

Permalink
Deprecate json decode functionality in UnicodeStringSet (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmphilli authored Jun 9, 2017
1 parent 19eeb5a commit 538f0c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
16 changes: 1 addition & 15 deletions pynamodb/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,7 @@ def element_serialize(self, value):
return six.u(str(value))

def element_deserialize(self, value):
"""
This deserializes what we get from mongo back into a str
Serialization previously json encoded strings. This caused them to have
extra double quote (") characters. That no longer happens.
This method allows both types of serialized values to be read
:param value:
:return:
"""
result = value
try:
result = json.loads(value)
except ValueError:
# it's serialized in the new way so pass
pass
return result
return value

def serialize(self, value):
if value is not None:
Expand Down
31 changes: 23 additions & 8 deletions pynamodb/tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ def test_unicode_set_serialize(self):
expected = sorted([six.u('foo'), six.u('bar')])
assert attr.serialize(set([six.u('foo'), six.u('bar')])) == expected

expected = sorted([six.u('True'), six.u('False')])
assert attr.serialize(set([six.u('True'), six.u('False')])) == expected

expected = sorted([six.u('true'), six.u('false')])
assert attr.serialize(set([six.u('true'), six.u('false')])) == expected

def test_round_trip_unicode_set(self):
"""
Round trip a unicode set
Expand All @@ -373,6 +379,15 @@ def test_round_trip_unicode_set(self):
orig = set([six.u('foo'), six.u('bar')])
assert orig == attr.deserialize(attr.serialize(orig))

orig = set([six.u('true'), six.u('false')])
assert orig == attr.deserialize(attr.serialize(orig))

orig = set([six.u('1'), six.u('2.8')])
assert orig == attr.deserialize(attr.serialize(orig))

orig = set([six.u('[1,2,3]'), six.u('2.8')])
assert orig == attr.deserialize(attr.serialize(orig))

def test_unicode_set_deserialize(self):
"""
UnicodeSetAttribute.deserialize
Expand All @@ -381,14 +396,14 @@ def test_unicode_set_deserialize(self):
value = set([six.u('foo'), six.u('bar')])
assert attr.deserialize(value) == value

def test_unicode_set_deserialize_old_way(self):
"""
UnicodeSetAttribute.deserialize old way
"""
attr = UnicodeSetAttribute()
value = set([six.u('foo'), six.u('bar')])
old_value = set([json.dumps(val) for val in value])
assert attr.deserialize(old_value) == value
value = set([six.u('True'), six.u('False')])
assert attr.deserialize(value) == value

value = set([six.u('true'), six.u('false')])
assert attr.deserialize(value) == value

value = set([six.u('1'), six.u('2.8')])
assert attr.deserialize(value) == value

def test_unicode_set_attribute(self):
"""
Expand Down

0 comments on commit 538f0c5

Please sign in to comment.