Fixed handle_decimals to raise a TypeError if it can't encode the object#1100
Closed
subssn21 wants to merge 3 commits intoaws:masterfrom
subssn21:JSONIssue
Closed
Fixed handle_decimals to raise a TypeError if it can't encode the object#1100subssn21 wants to merge 3 commits intoaws:masterfrom subssn21:JSONIssue
subssn21 wants to merge 3 commits intoaws:masterfrom
subssn21:JSONIssue
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1100 +/- ##
==========================================
+ Coverage 95.47% 95.52% +0.04%
==========================================
Files 27 27
Lines 4577 4577
Branches 579 579
==========================================
+ Hits 4370 4372 +2
+ Misses 135 134 -1
+ Partials 72 71 -1
Continue to review full report at Codecov.
|
stealthycoin
approved these changes
May 6, 2019
Contributor
|
Thank you for the contribution, I pushed a changelog commit, and changed the name of a function to make more sense in the context of the stack trace it generates. New PR: #1117. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
Description of changes:
default Json Encoders should raise a TypeError if they can't properly encode an object.
At the moment when you try to encode an object that is not JSON serializable you get:
[ERROR] ValueError: Circular reference detected
Traceback (most recent call last):
File "/var/task/chalice/app.py", line 820, in call
response = response.to_dict(self.api.binary_types)
File "/var/task/chalice/app.py", line 352, in to_dict
default=handle_decimals)
File "/var/lang/lib/python3.7/json/init.py", line 238, in dumps
**kw).encode(obj)
File "/var/lang/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/var/lang/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
Now you get:
[ERROR] TypeError: Object of type dict_values is not JSON serializable
Traceback (most recent call last):
File "/var/task/chalice/app.py", line 820, in call
response = response.to_dict(self.api.binary_types)
File "/var/task/chalice/app.py", line 352, in to_dict
default=handle_decimals)
File "/var/lang/lib/python3.7/json/init.py", line 238, in dumps
**kw).encode(obj)
File "/var/lang/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/var/lang/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/var/task/chalice/app.py", line 55, in handle_decimals
raise TypeError('Object of type %s is not JSON serializable' % obj.class.name)
which conforms to what Python expects:
https://docs.python.org/2/library/json.html#json.JSONEncoder
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.