mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
Sanitize NaN, Infinite, -Infinite causing error when saving as PostgreSQL JSON #7339 (2nd try) (#7348)
* Sanitize NaN, Infinite, -Infinite causing error when saving as PostgreSQL JSON #7339 (2nd try) * Move json nsanitaize to on the top of json_dumps * Fix comment
This commit is contained in:
31
tests/utils/test_json_dumps.py
Normal file
31
tests/utils/test_json_dumps.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from redash.utils import json_dumps, json_loads
|
||||
from tests import BaseTestCase
|
||||
|
||||
|
||||
class TestJsonDumps(BaseTestCase):
|
||||
"""
|
||||
NaN, Inf, and -Inf are sanitized to None.
|
||||
"""
|
||||
|
||||
def test_data_with_nan_is_sanitized(self):
|
||||
input_data = {
|
||||
"columns": [
|
||||
{"name": "_col0", "friendly_name": "_col0", "type": "float"},
|
||||
{"name": "_col1", "friendly_name": "_col1", "type": "float"},
|
||||
{"name": "_col2", "friendly_name": "_col1", "type": "float"},
|
||||
{"name": "_col3", "friendly_name": "_col1", "type": "float"},
|
||||
],
|
||||
"rows": [{"_col0": 1.0, "_col1": float("nan"), "_col2": float("inf"), "_col3": float("-inf")}],
|
||||
}
|
||||
expected_output_data = {
|
||||
"columns": [
|
||||
{"name": "_col0", "friendly_name": "_col0", "type": "float"},
|
||||
{"name": "_col1", "friendly_name": "_col1", "type": "float"},
|
||||
{"name": "_col2", "friendly_name": "_col1", "type": "float"},
|
||||
{"name": "_col3", "friendly_name": "_col1", "type": "float"},
|
||||
],
|
||||
"rows": [{"_col0": 1.0, "_col1": None, "_col2": None, "_col3": None}],
|
||||
}
|
||||
json_data = json_dumps(input_data)
|
||||
actual_output_data = json_loads(json_data)
|
||||
self.assertEquals(actual_output_data, expected_output_data)
|
||||
Reference in New Issue
Block a user