Skip to content

Commit

Permalink
Fix a few more inconsistencies when loading and dumping JSON. (getred…
Browse files Browse the repository at this point in the history
…ash#3626)

* Fix a few more inconsistencies when loading and dumping JSON.

Refs getredash#2807. Original work in: getredash#2817

These change have been added since c2429e9.

* Review fixes.
  • Loading branch information
jezdez authored and harveyrendell committed Nov 14, 2019
1 parent e6be836 commit d992b5c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
4 changes: 2 additions & 2 deletions redash/authentication/jwt_auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import json
import jwt
import requests
import simplejson

logger = logging.getLogger('jwt_auth')

Expand All @@ -21,7 +21,7 @@ def get_public_keys(url):
if 'keys' in data:
public_keys = []
for key_dict in data['keys']:
public_key = jwt.algorithms.RSAAlgorithm.from_jwk(json.dumps(key_dict))
public_key = jwt.algorithms.RSAAlgorithm.from_jwk(simplejson.dumps(key_dict))
public_keys.append(public_key)

get_public_keys.key_cache[url] = public_keys
Expand Down
10 changes: 4 additions & 6 deletions redash/monitor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import ast
import itertools
import json
import base64
from sqlalchemy import union_all
from redash import redis_connection, __version__, settings
from redash.models import db, DataSource, Query, QueryResult, Dashboard, Widget
from redash.utils import json_loads
from redash.worker import celery


Expand Down Expand Up @@ -74,9 +72,9 @@ def get_status():
def get_waiting_in_queue(queue_name):
jobs = []
for raw in redis_connection.lrange(queue_name, 0, -1):
job = json.loads(raw)
job = json_loads(raw)
try:
args = json.loads(job['headers']['argsrepr'])
args = json_loads(job['headers']['argsrepr'])
if args.get('query_id') == 'adhoc':
args['query_id'] = None
except ValueError:
Expand Down Expand Up @@ -114,7 +112,7 @@ def parse_tasks(task_lists, state):

if task['name'] == 'redash.tasks.execute_query':
try:
args = json.loads(task['args'])
args = json_loads(task['args'])
except ValueError:
args = {}

Expand Down
8 changes: 3 additions & 5 deletions redash/query_runner/db2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import os
import json
import logging

from redash.query_runner import *
from redash.utils import JSONEncoder
from redash.utils import json_dumps, json_loads

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -82,7 +80,7 @@ def _get_definitions(self, schema, query):
if error is not None:
raise Exception("Failed getting schema.")

results = json.loads(results)
results = json_loads(results)

for row in results['rows']:
if row['TABLE_SCHEMA'] != u'public':
Expand Down Expand Up @@ -129,7 +127,7 @@ def run_query(self, query, user):

data = {'columns': columns, 'rows': rows}
error = None
json_data = json.dumps(data, cls=JSONEncoder)
json_data = json_dumps(data)
else:
error = 'Query completed but it returned no data.'
json_data = None
Expand Down
5 changes: 2 additions & 3 deletions redash/query_runner/kylin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import os
import json
import logging
import requests
from requests.auth import HTTPBasicAuth

from redash import settings
from redash.query_runner import *
from redash.utils import JSONEncoder
from redash.utils import json_dumps

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -102,7 +101,7 @@ def run_query(self, query, user):
columns = self.get_columns(data['columnMetas'])
rows = self.get_rows(columns, data['results'])

return json.dumps({'columns': columns, 'rows': rows}), None
return json_dumps({'columns': columns, 'rows': rows}), None

def get_schema(self, get_stats=False):
url = self.configuration['url']
Expand Down
6 changes: 2 additions & 4 deletions redash/query_runner/rockset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import requests
import os
from redash.query_runner import *
from redash.utils import JSONEncoder
import json
from redash.utils import json_dumps


def _get_type(value):
Expand Down Expand Up @@ -96,7 +94,7 @@ def run_query(self, query, user):
columns = []
for k in rows[0]:
columns.append({'name': k, 'friendly_name': k, 'type': _get_type(rows[0][k])})
data = json.dumps({'columns': columns, 'rows': rows}, cls=JSONEncoder)
data = json_dumps({'columns': columns, 'rows': rows})
return data, None


Expand Down
7 changes: 3 additions & 4 deletions redash/query_runner/uptycs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from redash.query_runner import *
from redash.utils import json_dumps
from redash.utils import json_dumps, json_loads

import json
import jwt
import datetime
import requests
Expand Down Expand Up @@ -93,7 +92,7 @@ def api_call(self, sql):
True))

if response.status_code == 200:
response_output = json.loads(response.content)
response_output = json_loads(response.content)
else:
error = 'status_code ' + str(response.status_code) + '\n'
error = error + "failed to connect"
Expand Down Expand Up @@ -124,7 +123,7 @@ def get_schema(self, get_stats=False):
verify=self.configuration.get('verify_ssl',
True))
redash_json = []
schema = json.loads(response.content)
schema = json_loads(response.content)
for each_def in schema['tables']:
table_name = each_def['name']
columns = []
Expand Down

0 comments on commit d992b5c

Please sign in to comment.