Skip to content

Commit

Permalink
refactor sql_json view endpoint: extract to method reuse code (#16546)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofekisr authored Sep 1, 2021
1 parent 80c39da commit e947f8a
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2411,8 +2411,9 @@ def validate_sql_json(
return json_error_response(f"{msg}", status=400)
return json_error_response(f"{msg}")

@staticmethod
def _sql_json_async(
@classmethod
def _sql_json_async( # pylint: disable=too-many-arguments
cls,
session: Session,
rendered_query: str,
query: Query,
Expand Down Expand Up @@ -2474,19 +2475,13 @@ def _sql_json_async(
# Update saved query with execution info from the query execution
QueryDAO.update_saved_query_exec_info(query_id)

resp = json_success(
json.dumps(
{"query": query.to_dict()},
default=utils.json_int_dttm_ser,
ignore_nan=True,
),
status=202,
)
resp = json_success(cls._convert_query_to_payload(query), status=202,)
session.commit()
return resp

@staticmethod
@classmethod
def _sql_json_sync(
cls,
_session: Session,
rendered_query: str,
query: Query,
Expand Down Expand Up @@ -2723,6 +2718,14 @@ def sql_json_exec( # pylint: disable=too-many-statements,too-many-locals
session, rendered_query, query, expand_data, log_params
)

@staticmethod
def _convert_query_to_payload(query: Query) -> str:
return json.dumps(
{"query": query.to_dict()},
default=utils.json_int_dttm_ser,
ignore_nan=True,
)

@classmethod
def _get_the_query_db(
cls, execution_context: SqlJsonExecutionContext, session: Session
Expand Down

0 comments on commit e947f8a

Please sign in to comment.