-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Sanitize NaN, Infinite, -Infinite causing error when saving as PostgreSQL JSON #7339
base: master
Are you sure you want to change the base?
Sanitize NaN, Infinite, -Infinite causing error when saving as PostgreSQL JSON #7339
Conversation
3c3af98
to
e6b5028
Compare
I think this operation is unnecessary, NaN is not a numeric type and should not be forced to be stored. |
Each database or data engine handles it differently, for NaN and others situation, so I think this situation should not be handled. They should abide by their original system internal processing methods. |
@gaecoli
https://simplejson.readthedocs.io/en/latest/
|
@arikfr If u have free time, please review this PR! Thank you! |
This PR addresses #6992 |
I looked into this issue in detail and it really should be fixed. @yoshiokatsuneo @cj-matteo-cafasso |
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.
Thank you for addressing this @yoshiokatsuneo !
The error comes from json_dumps
passing allow_nan=False
in json_dumps
which was indeed introduced in the PR mentinoed.
How about we move this logic (of turning NaN/Inf to None) to json_dumps
instead of calling it here?
How about testing orjson? orjson.dumps() converts NaN float to null. |
@EugeneChung would you like to open a PR that switches to orjson? |
…eSQL JSON getredash#7339 (2nd try)
Thank you for your comment ! |
What type of PR is this?
Description
When running query that output NaN, Infinite, or -Infinite, redash executor crashes with the error "Out of range float values are not JSON compliant" like below. Redash does not output any rows when the error was occurred.
The error occurs because JSON(PostgreSQL JSON type) does not support NaN, Infinite, -Infinite.
This PR fixes the issue by sanitize NaN, Infinite, -Infinite value to None. This is the save behavior that JavaScript JSON.stringify() does.
We can reproduce the issue by running following query on BigQuery or PostgreSQL.
BigQuery:
PostgreSQL:
The issue was introduced by #6685 which removes simplejson. Before #6685 , NaN / Inf was converted to null by simplejson with ignore_nan=True. This PR change behavior for NaN/Inf as same as before #6685 .
How is this tested?
Unit test was added.
Also, we can confirm by running the query on the description.
Before this PR:
After this PR: