Skip to content

Commit

Permalink
try importing within init
Browse files Browse the repository at this point in the history
  • Loading branch information
guidopetri committed Feb 10, 2024
1 parent 7e110a6 commit 5b67199
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 3 additions & 1 deletion redash/query_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from sshtunnel import open_tunnel

from redash import settings, utils
from redash.query_runner.registry import query_runners
from redash.utils.requests_session import (
UnacceptableAddressException,
requests_or_advocate,
Expand Down Expand Up @@ -396,6 +395,9 @@ def get_response(self, url, auth=None, http_method="get", **kwargs):
return response, error


query_runners = {}


def register(query_runner_class):
global query_runners
if query_runner_class.enabled():
Expand Down
1 change: 0 additions & 1 deletion redash/query_runner/registry.py

This file was deleted.

6 changes: 3 additions & 3 deletions redash/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from sqlalchemy.orm.query import Query

from redash import settings
from redash.query_runner.registry import query_runners

from .human_time import parse_human_time

Expand Down Expand Up @@ -75,15 +74,16 @@ class JSONEncoder(json.JSONEncoder):
"""Adapter for `json.dumps`."""

def __init__(self, **kwargs):
from redash.query_runner import query_runners

self.encoders = [r.custom_json_encoder for r in query_runners.values() if hasattr(r, "custom_json_encoder")]
super().__init__(**kwargs)

def default(self, o):
for encoder in self.encoders:
result = encoder(self, o)
if result:
o = result
break
return result
if isinstance(o, Query):
result = list(o)
elif isinstance(o, decimal.Decimal):
Expand Down

0 comments on commit 5b67199

Please sign in to comment.