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

  1. 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.
  2. Upgrade Superset and the relevant DBAPI driver — cancel support has been added to more engines over time.
  3. Set a realistic SQL_LAB_TIMEOUT / query timeout so runaway queries terminate even when cancel is unavailable.
  4. 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

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


AI-assisted analysis of apache/superset@f4587218dd (2026-08-14). Data as JSON: /api/errors/6291ad6c34cb6ebe. Report an issue: GitHub.