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 8cd5dd0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 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
23 changes: 15 additions & 8 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"
}
}
"""
self.assertRaises(messages.DecodeError, protojson.decode_message,
MyMessage, encoded)
for encoded in (
"""{
"a_nested_datetime": {
"nested_dt_value": "invalid"
}
}
""",
"""{
"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 8cd5dd0

Please sign in to comment.