-
Notifications
You must be signed in to change notification settings - Fork 197
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
handle Decimal on amount values #364
base: master
Are you sure you want to change the base?
Conversation
I'd just like to express a desire to have this PR merged into master. Our program works fine on 0.9.8, but fails in 0.9.9+ due to this jsonEncoder issue |
Let me know if there is anything else I can do to get this merged. |
Pinging this again would love to get this out. |
I'm also running into this on a formerly working deployment - not sure exactly where it broke for me or which set of conditions are the trigger, but I'm pretty confident that the issue is the same :( |
Could you test with this branch and see if it fixes the issue? |
Well... your single user test passed for me! ;-) |
Hi class ToJsonMixin(object):
def to_json(self):
return json.dumps(self, default=self.json_filter(), sort_keys=True, indent=4)
def json_filter(self):
"""
filter out properties that have names starting with _
or properties that have a value of None
"""
return lambda obj: str(obj) if isinstance(obj, decimal.Decimal) else dict((k, v) for k, v in obj.__dict__.items()
if not k.startswith('_') and getattr(obj, k) is not None) |
I added a unit test that can help you play with your fix. I didn't get it to work well in the bill example with nested objects. |
In the testing on my project the jsonEncoder in newer versions of python calls default for both keys and values. This means that you get an exception if you pass in Decimal as a line amount on newer versions of python with the existing lambda on default.
I think we should also include a test where a bill is created with a decimal line amount and to_json() is called to ensure there is no exception.