{"record":{"id":"6291ad6c34cb6ebe","repo":"apache/superset","slug":"could-not-cancel-query","errorCode":null,"errorMessage":"Could not cancel query","messagePattern":"Could not cancel query","errorType":"exception","errorClass":"SupersetCancelQueryException","httpStatus":422,"severity":"warning","filePath":"superset/daos/query.py","lineNumber":82,"sourceCode":"            db.session.query(Query)\n            .filter(Query.client_id == client_id, Query.user_id == get_user_id())\n            .one_or_none()\n        )\n        if not query:\n            raise QueryNotFoundException(f\"Query with client_id {client_id} not found\")\n\n        if query.status in [\n            QueryStatus.FAILED,\n            QueryStatus.SUCCESS,\n            QueryStatus.TIMED_OUT,\n        ]:\n            logger.warning(\n                \"Query with client_id could not be stopped: query already complete\",\n            )\n            return\n\n        if not sql_lab.cancel_query(query):\n            raise SupersetCancelQueryException(\"Could not cancel query\")\n\n        query.status = QueryStatus.STOPPED\n        query.end_time = now_as_float()\n\n\nclass SavedQueryDAO(BaseDAO[SavedQuery]):\n    base_filter = SavedQueryFilter\n","sourceCodeStart":64,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/daos/query.py#L64-L90","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"# before\nQueryDAO.stop_query(client_id)  # engine can't cancel -> SupersetCancelQueryException (422)\n\n# after\nfrom superset.exceptions import SupersetCancelQueryException\ntry:\n    QueryDAO.stop_query(client_id)\nexcept SupersetCancelQueryException:\n    # engine lacks cancel support: rely on timeout instead\n    logger.warning('cancel unsupported for engine %s; waiting for timeout', database.db_engine_spec.__name__)","handlingStrategy":"fallback","validationCode":"def engine_supports_cancel(database) -> bool:\n    spec = database.db_engine_spec\n    return spec.has_implementation('cancel_query') or callable(getattr(spec, 'cancel_query', None)) and spec.cancel_query is not __class__.__dict__.get('cancel_query')","typeGuard":null,"tryCatchPattern":"from superset.exceptions import SupersetCancelQueryException\ntry:\n    QueryDAO.stop_query(client_id)\nexcept SupersetCancelQueryException:\n    # engine cannot cancel; fall back to waiting for SQL_LAB_TIMEOUT\n    notify_user('cancel unsupported for this database; query will time out')","preventionTips":["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."],"tags":["sql-lab","query","cancellation","engine-spec","database"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}