apache/superset · warning · SupersetCancelQueryException
Could not cancel query
Error message
Could not cancel query
What it means
Raised by QueryDAO.stop_query when the query is still in a non-terminal state but sql_lab.cancel_query(query) returns False, meaning the database engine adapter could not (or does not support) cancelling the running statement. It is a SupersetCancelQueryException with status 422. Note the DAO first short-circuits for already-terminal statuses (FAILED/SUCCESS/TIMED_OUT) with only a warning, so this error specifically means 'still running, cancellation refused'.
Source
Thrown at superset/daos/query.py:82
db.session.query(Query)
.filter(Query.client_id == client_id, Query.user_id == get_user_id())
.one_or_none()
)
if not query:
raise QueryNotFoundException(f"Query with client_id {client_id} not found")
if query.status in [
QueryStatus.FAILED,
QueryStatus.SUCCESS,
QueryStatus.TIMED_OUT,
]:
logger.warning(
"Query with client_id could not be stopped: query already complete",
)
return
if not sql_lab.cancel_query(query):
raise SupersetCancelQueryException("Could not cancel query")
query.status = QueryStatus.STOPPED
query.end_time = now_as_float()
class SavedQueryDAO(BaseDAO[SavedQuery]):
base_filter = SavedQueryFilter
View on GitHub (pinned to f4587218dd)
Solutions
- Check whether your database engine spec implements cancel_query / cancel_query_engine; if not, cancellation is unsupported and you must wait for the query to finish or time out.
- Upgrade Superset and the relevant DBAPI driver — cancel support has been added to more engines over time.
- Set a realistic SQL_LAB_TIMEOUT / query timeout so runaway queries terminate even when cancel is unavailable.
- If cancel is implemented but fails intermittently, retry after confirming the query is still in a running state (it may have completed in between).
Example fix
# before
QueryDAO.stop_query(client_id) # engine can't cancel -> SupersetCancelQueryException (422)
# after
from superset.exceptions import SupersetCancelQueryException
try:
QueryDAO.stop_query(client_id)
except SupersetCancelQueryException:
# engine lacks cancel support: rely on timeout instead
logger.warning('cancel unsupported for engine %s; waiting for timeout', database.db_engine_spec.__name__) Defensive patterns
Strategy: fallback
Validate before calling
def engine_supports_cancel(database) -> bool:
spec = database.db_engine_spec
return spec.has_implementation('cancel_query') or callable(getattr(spec, 'cancel_query', None)) and spec.cancel_query is not __class__.__dict__.get('cancel_query') Try / catch
from superset.exceptions import SupersetCancelQueryException
try:
QueryDAO.stop_query(client_id)
except SupersetCancelQueryException:
# engine cannot cancel; fall back to waiting for SQL_LAB_TIMEOUT
notify_user('cancel unsupported for this database; query will time out') Prevention
- Check the engine spec's cancel support before exposing a Stop button for that database type.
- Set realistic query timeouts so unsupported engines still self-terminate.
- Keep DBAPI drivers current; cancel support varies by driver version.
When it happens
Trigger: Running SQL Lab queries against an engine whose adapter has no cancel implementation (cancel_query returns None/False by default); the engine-specific kill command fails because the database connection for cancelling cannot be established; the server-side process id could not be resolved for the running statement.
Common situations: Using less-common databases (some JDBC-over-pyodbc engines, older drivers) where Superset's engine adapter lacks cancel support; heavy load on the metadata or target database making the cancel connection time out; queries in a state (e.g. scheduling) the engine cannot interrupt.
Related errors
- The database referenced in this query was not found. Please
- Error: %(error)s
- Field is required
- Connection failed, please check your connection settings
- Database could not be created.
AI-assisted analysis of apache/superset@f4587218dd (2026-08-14).
Data as JSON: /api/errors/6291ad6c34cb6ebe.
Report an issue: GitHub.