Skip to content

Commit

Permalink
[hotfix] fix pending queries race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Mar 30, 2017
1 parent 0a1d8db commit 6b52384
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion superset/sql_lab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import celery
from time import sleep
from datetime import datetime
import json
import logging
Expand Down Expand Up @@ -54,7 +55,16 @@ def get_sql_results(self, query_id, return_results=True, store_results=False):
else:
session = db.session()
session.commit() # HACK
query = session.query(models.Query).filter_by(id=query_id).one()
try:
query = session.query(models.Query).filter_by(id=query_id).one()
except Exception as e:
logging.error("Query with id `{}` could not be retrieved".format(query_id))
logging.error("Sleeping for a sec and retrying...")
# Nasty hack to get around a race condition where the worker
# cannot find the query it's supposed to run
sleep(1)
query = session.query(models.Query).filter_by(id=query_id).one()

database = query.database
db_engine_spec = database.db_engine_spec
db_engine_spec.patch()
Expand Down
4 changes: 4 additions & 0 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,10 @@ def sql_json(self):
session.add(query)
session.flush()
query_id = query.id
session.commit() # shouldn't be necessary
if not query_id:
raise Exception("Query record was not created as expected.")
logging.info("Triggering query_id: {}".format(query_id))

# Async request.
if async:
Expand Down

0 comments on commit 6b52384

Please sign in to comment.