Skip to content

Commit

Permalink
Merge branch 'master' into issue-6640
Browse files Browse the repository at this point in the history
  • Loading branch information
masayuki038 authored Feb 10, 2024
2 parents dd60abb + 939bec2 commit 8ea665e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 41 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-python@v4
with:
python-version: '3.8'
Expand All @@ -38,10 +38,10 @@ jobs:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
ref: ${{ github.event.pull_request.head.sha }}
- name: Build Docker Images
run: |
set -x
Expand Down Expand Up @@ -78,10 +78,10 @@ jobs:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand All @@ -105,10 +105,10 @@ jobs:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand Down Expand Up @@ -138,10 +138,10 @@ jobs:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand Down Expand Up @@ -208,10 +208,10 @@ jobs:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand Down
12 changes: 6 additions & 6 deletions redash/query_runner/cass.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ def generate_ssl_options_dict(protocol, cert_path=None):
return ssl_options


def custom_json_encoder(dec, o):
if isinstance(o, sortedset):
return list(o)
return None


class Cassandra(BaseQueryRunner):
noop_query = "SELECT dateof(now()) FROM system.local"

@classmethod
def enabled(cls):
return enabled

@classmethod
def custom_json_encoder(cls, dec, o):
if isinstance(o, sortedset):
return list(o)
return None

@classmethod
def configuration_schema(cls):
return {
Expand Down
20 changes: 10 additions & 10 deletions redash/query_runner/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@
}


def custom_json_encoder(dec, o):
if isinstance(o, ObjectId):
return str(o)
elif isinstance(o, Timestamp):
return dec.default(o.as_datetime())
elif isinstance(o, Decimal128):
return o.to_decimal()
return None


date_regex = re.compile(r'ISODate\("(.*)"\)', re.IGNORECASE)


Expand Down Expand Up @@ -171,6 +161,16 @@ def __init__(self, configuration):
True if "replicaSetName" in self.configuration and self.configuration["replicaSetName"] else False
)

@classmethod
def custom_json_encoder(cls, dec, o):
if isinstance(o, ObjectId):
return str(o)
elif isinstance(o, Timestamp):
return dec.default(o.as_datetime())
elif isinstance(o, Decimal128):
return o.to_decimal()
return None

def _get_db(self):
kwargs = {}
if self.is_replica_set:
Expand Down
24 changes: 12 additions & 12 deletions redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@
}


def custom_json_encoder(dec, o):
if isinstance(o, Range):
# From: https://github.com/psycopg/psycopg2/pull/779
if o._bounds is None:
return ""

items = [o._bounds[0], str(o._lower), ", ", str(o._upper), o._bounds[1]]

return "".join(items)
return None


def _wait(conn, timeout=None):
while 1:
try:
Expand Down Expand Up @@ -195,6 +183,18 @@ def configuration_schema(cls):
def type(cls):
return "pg"

@classmethod
def custom_json_encoder(cls, dec, o):
if isinstance(o, Range):
# From: https://github.com/psycopg/psycopg2/pull/779
if o._bounds is None:
return ""

items = [o._bounds[0], str(o._lower), ", ", str(o._upper), o._bounds[1]]

return "".join(items)
return None

def _get_definitions(self, schema, query):
results, error = self.run_query(query, None)

Expand Down
4 changes: 3 additions & 1 deletion redash/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ class JSONEncoder(json.JSONEncoder):
"""Adapter for `json.dumps`."""

def __init__(self, **kwargs):
self.encoders = [m.custom_json_encoder for m in sys.modules.values() if hasattr(m, "custom_json_encoder")]
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):
Expand Down

0 comments on commit 8ea665e

Please sign in to comment.