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 2, 2020
1 parent ca20945 commit ec11b47
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,14 +374,21 @@ def testDecodeInvalidDateTime(self):
MyMessage, '{"a_datetime": "invalid"}')

def testDecodeInvalidMessage(self):
encoded = """{
"a_nested_datetime": {
"nested_dt_value": "invalid"
for encoded in (
"""{
"a_nested_datetime": {
"nested_dt_value": "invalid"
}
}
}
"""
self.assertRaises(messages.DecodeError, protojson.decode_message,
MyMessage, encoded)
""",
"""{
"a_nested_datetime": [{
"nested_dt_value": "2012-09-30T15:31:50.262"
}]
}
"""):
self.assertRaises(messages.DecodeError, protojson.decode_message,
MyMessage, encoded)

def testEncodeDateTime(self):
for datetime_string, datetime_vals in (
Expand Down

0 comments on commit ec11b47

Please sign in to comment.