Skip to content

Commit 087ac0b

Browse files
committed
Fix unexpected attribute error
1 parent ca20945 commit 087ac0b

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

apitools/base/protorpclite/protojson.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ def decode_field(self, field, value):
333333

334334
elif (isinstance(field, messages.MessageField) and
335335
issubclass(field.type, messages.Message)):
336-
return self.__decode_dictionary(field.type, value)
336+
try:
337+
return self.__decode_dictionary(field.type, value)
338+
except AttributeError as err:
339+
raise messages.DecodeError(err)
337340

338341
elif (isinstance(field, messages.FloatField) and
339342
isinstance(value, (six.integer_types, six.string_types))):

apitools/base/protorpclite/protojson_test.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,20 @@ def testDecodeInvalidDateTime(self):
374374
MyMessage, '{"a_datetime": "invalid"}')
375375

376376
def testDecodeInvalidMessage(self):
377-
encoded = """{
378-
"a_nested_datetime": {
379-
"nested_dt_value": "invalid"
380-
}
381-
}
382-
"""
383-
self.assertRaises(messages.DecodeError, protojson.decode_message,
377+
for encoded in (
378+
"""{
379+
"a_nested_datetime": {
380+
"nested_dt_value": "invalid"
381+
}
382+
}
383+
""",
384+
"""{
385+
"a_nested_array": [{
386+
"an_integer": 1
387+
}]
388+
}
389+
"""):
390+
self.assertRaises(messages.DecodeError, protojson.decode_message,
384391
MyMessage, encoded)
385392

386393
def testEncodeDateTime(self):

0 commit comments

Comments
 (0)