Skip to content

Commit

Permalink
Fix unexpected attribute error
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbarosan committed Oct 1, 2020
1 parent ca20945 commit 087ac0b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion apitools/base/protorpclite/protojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ def decode_field(self, field, value):

elif (isinstance(field, messages.MessageField) and
issubclass(field.type, messages.Message)):
return self.__decode_dictionary(field.type, value)
try:
return self.__decode_dictionary(field.type, value)
except AttributeError as err:
raise messages.DecodeError(err)

elif (isinstance(field, messages.FloatField) and
isinstance(value, (six.integer_types, six.string_types))):
Expand Down
21 changes: 14 additions & 7 deletions apitools/base/protorpclite/protojson_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,20 @@ def testDecodeInvalidDateTime(self):
MyMessage, '{"a_datetime": "invalid"}')

def testDecodeInvalidMessage(self):
encoded = """{
"a_nested_datetime": {
"nested_dt_value": "invalid"
}
}
"""
self.assertRaises(messages.DecodeError, protojson.decode_message,
for encoded in (
"""{
"a_nested_datetime": {
"nested_dt_value": "invalid"
}
}
""",
"""{
"a_nested_array": [{
"an_integer": 1
}]
}
"""):
self.assertRaises(messages.DecodeError, protojson.decode_message,
MyMessage, encoded)

def testEncodeDateTime(self):
Expand Down

0 comments on commit 087ac0b

Please sign in to comment.