-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix JSON encoding of decimal.Decimal #69
Conversation
Version `0.6.0` forces validation of `Call`s before the are send to the other end. The validation of `call.SetChargingProfilePayload` fails with a TypeError. The charging profile contains a value of type `decimal.Decimal` and this value cannot be serialized to JSON. The problem can be demonstrated like this: >>> import decimal >>> import json >>> >>> json.dumps(decimal.Decimal(3)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/developer/.pyenv/versions/3.7.0/lib/python3.7/json/__init__.py", line 231, in dumps return _default_encoder.encode(obj) File "/home/developer/.pyenv/versions/3.7.0/lib/python3.7/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/home/developer/.pyenv/versions/3.7.0/lib/python3.7/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/home/developer/.pyenv/versions/3.7.0/lib/python3.7/json/encoder.py", line 179, in default raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type Decimal is not JSON serializable This bug has been fixed by creating a custom enconder for `decimal.Decimal`. Fixes: #68
DeepCode's analysis on #bc13ea found:
💬 This comment has been generated by the DeepCode bot, installed by the owner of the repository. The DeepCode bot protects your repository by detecting and commenting on security vulnerabilities or other critical issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small comment but otherwise looks good.
Version `0.6.0` forces validation of `Call`s before the are send to the other end. The validation of `call.SetChargingProfilePayload` fails with a TypeError. The charging profile contains a value of type `decimal.Decimal` and this value cannot be serialized to JSON. The problem can be demonstrated like this: >>> import decimal >>> import json >>> >>> json.dumps(decimal.Decimal(3)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/developer/.pyenv/versions/3.7.0/lib/python3.7/json/__init__.py", line 231, in dumps return _default_encoder.encode(obj) File "/home/developer/.pyenv/versions/3.7.0/lib/python3.7/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/home/developer/.pyenv/versions/3.7.0/lib/python3.7/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/home/developer/.pyenv/versions/3.7.0/lib/python3.7/json/encoder.py", line 179, in default raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type Decimal is not JSON serializable This bug has been fixed by creating a custom enconder for `decimal.Decimal`. Fixes: mobilityhouse#68
Version
0.6.0
forces validation ofCall
s before they are send to theother end. The validation of
call.SetChargingProfilePayload
fails witha TypeError. The charging profile contains a value of type
decimal.Decimal
and this value cannot be serialized to JSON. Theproblem can be demonstrated like this:
This bug has been fixed by creating a custom enconder for
decimal.Decimal
.Fixes: #68