I'm getting an item from a DynamoDB Table that has a set attribute. Simply returning the item at the end of the request through Chalice raises this error.
[ERROR] TypeError: Object of type set is not JSON serializable
Traceback (most recent call last):
File "/var/task/chalice/app.py", line 1239, in __call__
return handler(event, context)
File "/var/task/chalice/app.py", line 1672, in __call__
return response.to_dict(self.api.binary_types)
File "/var/task/chalice/app.py", line 473, in to_dict
body = json.dumps(body, separators=(',', ':'),
File "/var/lang/lib/python3.9/json/__init__.py", line 234, in dumps
return cls(
File "/var/lang/lib/python3.9/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/var/lang/lib/python3.9/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/var/task/chalice/app.py", line 64, in handle_extra_types
raise TypeError('Object of type %s is not JSON serializable'
That should work, but before writing a PR I want to make sure my solution is sound and maybe have some guidance on how to write a test for it. Currently it seems the only test where handle_extra_types is used is test_http_request_to_dict_is_json_serializable, but there is no test for the response.
I'm getting an item from a DynamoDB Table that has a set attribute. Simply returning the item at the end of the request through Chalice raises this error.
Chalice
Item in DynamoDB
Stack trace
Solution
Add:
To:
https://github.com/aws/chalice/blob/61f43459a078524b4d80cbb816bb4d5d67884a47/chalice/app.py#L55-L65
That should work, but before writing a PR I want to make sure my solution is sound and maybe have some guidance on how to write a test for it. Currently it seems the only test where
handle_extra_types
is used istest_http_request_to_dict_is_json_serializable
, but there is no test for the response.https://github.com/aws/chalice/blob/adcc8dbdb0ef86b7aa9238bf90e718c6cd3413f3/tests/unit/test_app.py#L1805