Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: sql_json view endpoint: extract to method for code reusing #16546

Merged
merged 1 commit into from
Sep 1, 2021
Merged
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
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