Skip to content

Commit

Permalink
Fix race condition when fetching results in SQL Lab (apache#7198)
Browse files Browse the repository at this point in the history
* Fix race condition when fetching results in SQL Lab

* Fix lint
  • Loading branch information
betodealmeida authored and xtinec committed Apr 2, 2019
1 parent 82cf553 commit ca6a73b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ def get_sql_results(
return handle_query_error(str(e), query, session)


def execute_sql_statement(
sql_statement, query, user_name, session,
cursor, return_results=False):
def execute_sql_statement(sql_statement, query, user_name, session, cursor):
"""Executes a single SQL statement"""
database = query.database
db_engine_spec = database.db_engine_spec
Expand Down Expand Up @@ -256,11 +254,9 @@ def execute_sql_statements(
logging.info(msg)
query.set_extra_json_key('progress', msg)
session.commit()
is_last_statement = i == len(statements) - 1
try:
cdf = execute_sql_statement(
statement, query, user_name, session, cursor,
return_results=is_last_statement and return_results)
statement, query, user_name, session, cursor)
msg = f'Running statement {i+1} out of {statement_count}'
except Exception as e:
msg = str(e)
Expand All @@ -282,7 +278,6 @@ def execute_sql_statements(
show_cols=False,
latest_partition=False)
query.end_time = now_as_float()
session.commit()

payload.update({
'status': query.status,
Expand Down
2 changes: 1 addition & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,7 @@ def sql_json(self):
database_id=int(database_id),
sql=sql,
schema=schema,
select_as_cta=request.form.get('select_as_cta') == 'true',
select_as_cta=select_as_cta,
start_time=now_as_float(),
tab_name=request.form.get('tab'),
status=QueryStatus.PENDING if async_ else QueryStatus.RUNNING,
Expand Down

0 comments on commit ca6a73b

Please sign in to comment.