Skip to content

Commit

Permalink
1.5.4 -- patch release to prepare for pull request #158 in 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinner-lyft committed Oct 17, 2017
1 parent ebbf334 commit 5cd038c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pynamodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"""
__author__ = 'Jharrod LaFon'
__license__ = 'MIT'
__version__ = '1.5.3'
__version__ = '1.5.4'
18 changes: 18 additions & 0 deletions pynamodb/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ class UnicodeSetAttribute(SetMixin, Attribute):
attr_type = STRING_SET
null = True

def element_deserialize(self, value):
"""
This prepares for a future serialization change in v1.6.0 which will stop
serializing json encoded strings. This method attempts to deserialize a json
encoded value and falls back to returning the raw value if json decoding fails.
"""
result = value
try:
result = json.loads(value)
except ValueError:
# it's serialized in the new way so pass
pass
return result

def deserialize(self, value):
if value and len(value):
return set([self.element_deserialize(val) for val in value])


class UnicodeAttribute(Attribute):
"""
Expand Down
17 changes: 15 additions & 2 deletions pynamodb/tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,22 @@ def test_unicode_set_deserialize(self):
UnicodeSetAttribute.deserialize
"""
attr = UnicodeSetAttribute()
value = set([six.u('foo'), six.u('bar')])
self.assertEqual(
attr.deserialize([json.dumps(val) for val in sorted(set([six.u('foo'), six.u('bar')]))]),
set([six.u('foo'), six.u('bar')])
attr.deserialize(value),
value
)

def test_unicode_set_deserialize_json(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])
self.assertEqual(
attr.deserialize(old_value),
value
)

def test_unicode_set_attribute(self):
Expand Down

0 comments on commit 5cd038c

Please sign in to comment.