Skip to content

Commit 5cd038c

Browse files
committed
1.5.4 -- patch release to prepare for pull request #158 in 1.6.0
1 parent ebbf334 commit 5cd038c

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

pynamodb/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
"""
88
__author__ = 'Jharrod LaFon'
99
__license__ = 'MIT'
10-
__version__ = '1.5.3'
10+
__version__ = '1.5.4'

pynamodb/attributes.py

+18
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ class UnicodeSetAttribute(SetMixin, Attribute):
140140
attr_type = STRING_SET
141141
null = True
142142

143+
def element_deserialize(self, value):
144+
"""
145+
This prepares for a future serialization change in v1.6.0 which will stop
146+
serializing json encoded strings. This method attempts to deserialize a json
147+
encoded value and falls back to returning the raw value if json decoding fails.
148+
"""
149+
result = value
150+
try:
151+
result = json.loads(value)
152+
except ValueError:
153+
# it's serialized in the new way so pass
154+
pass
155+
return result
156+
157+
def deserialize(self, value):
158+
if value and len(value):
159+
return set([self.element_deserialize(val) for val in value])
160+
143161

144162
class UnicodeAttribute(Attribute):
145163
"""

pynamodb/tests/test_attributes.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,22 @@ def test_unicode_set_deserialize(self):
353353
UnicodeSetAttribute.deserialize
354354
"""
355355
attr = UnicodeSetAttribute()
356+
value = set([six.u('foo'), six.u('bar')])
356357
self.assertEqual(
357-
attr.deserialize([json.dumps(val) for val in sorted(set([six.u('foo'), six.u('bar')]))]),
358-
set([six.u('foo'), six.u('bar')])
358+
attr.deserialize(value),
359+
value
360+
)
361+
362+
def test_unicode_set_deserialize_json(self):
363+
"""
364+
UnicodeSetAttribute.deserialize old way
365+
"""
366+
attr = UnicodeSetAttribute()
367+
value = set([six.u('foo'), six.u('bar')])
368+
old_value = set([json.dumps(val) for val in value])
369+
self.assertEqual(
370+
attr.deserialize(old_value),
371+
value
359372
)
360373

361374
def test_unicode_set_attribute(self):

0 commit comments

Comments
 (0)