Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion redash/query_runner/cass.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def generate_ssl_options_dict(protocol, cert_path=None):
return ssl_options


def json_encoder(dec, o):
def custom_json_encoder(dec, o):
if isinstance(o, sortedset):
return list(o)
return None
Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}


def json_encoder(dec, o):
def custom_json_encoder(dec, o):
if isinstance(o, ObjectId):
return str(o)
elif isinstance(o, Timestamp):
Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}


def json_encoder(dec, o):
def custom_json_encoder(dec, o):
if isinstance(o, Range):
# From: https://github.com/psycopg/psycopg2/pull/779
if o._bounds is None:
Expand Down
11 changes: 6 additions & 5 deletions redash/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ def generate_token(length):
return "".join(rand.choice(chars) for x in range(length))


json_encoders = [m.custom_json_encoder for m in sys.modules if hasattr(m, "custom_json_encoder")]


class JSONEncoder(json.JSONEncoder):
"""Adapter for `json.dumps`."""

def __init__(self, **kwargs):
self.encoders = json_encoders
self.encoders = [
m.custom_json_encoder
for m in sys.modules.values()
if hasattr(m, "custom_json_encoder")
]
super().__init__(**kwargs)

def default(self, o):
Expand Down Expand Up @@ -111,7 +112,7 @@ def default(self, o):
elif isinstance(o, bytes):
result = binascii.hexlify(o).decode()
else:
result = super(JSONEncoder, self).default(o)
result = super().default(o)
return result


Expand Down