{"record":{"id":"a67886cd20490bbf","repo":"apache/superset","slug":"failed-to-execute-query-s-exception-message","errorCode":null,"errorMessage":"Failed to execute %(query)s: {exception message}","messagePattern":"Failed to execute (.+?): (.+?)","errorType":"exception","errorClass":"SqlLabException","httpStatus":500,"severity":"error","filePath":"superset/commands/sql_lab/execute.py","lineNumber":125,"sourceCode":"            self._execution_context_convertor.set_payload(\n                self._execution_context, status\n            )\n\n            # save columns into metadata_json\n            self._query_dao.save_metadata(\n                self._execution_context.query, self._execution_context_convertor.payload\n            )\n\n            return {\n                \"status\": status,\n                \"payload\": self._execution_context_convertor.serialize_payload(),\n            }\n        except (SupersetErrorException, SupersetErrorsException):\n            # to make sure we raising the original\n            # SupersetErrorsException || SupersetErrorsException\n            raise\n        except Exception as ex:\n            raise SqlLabException(self._execution_context, exception=ex) from ex\n\n    def _try_get_existing_query(self) -> Query | None:\n        return self._query_dao.find_one_or_none(\n            client_id=self._execution_context.client_id,\n            user_id=self._execution_context.user_id,\n            sql_editor_id=self._execution_context.sql_editor_id,\n        )\n\n    @classmethod\n    def is_query_handled(cls, query: Query | None) -> bool:\n        return query is not None and query.status in [\n            QueryStatus.RUNNING,\n            QueryStatus.PENDING,\n            QueryStatus.TIMED_OUT,\n        ]\n\n    def _run_sql_json_exec_from_scratch(self) -> SqlJsonExecutionStatus:\n        self._execution_context.set_database(self._get_the_query_db())","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/sql_lab/execute.py#L107-L143","documentation":"Raised in ExecuteSqlCommand.run() (superset/commands/sql_lab/execute.py:125) as SqlLabException wrapping any exception that is not itself SupersetErrorException/SupersetErrorsException. It is the catch-all boundary for SQL execution: the original exception is chained (raise ... from ex) and paired with the execution context, so the true root cause (engine error, driver error, etc.) is in the __cause__, not this message. The message template 'Failed to execute %(query)s' gets the query text interpolated.","triggerScenarios":"Any unexpected failure during query dispatch — database driver errors, connection drops mid-execution, unexpected engine-spec exceptions, or serialization failures — anything the specialized Superset error paths do not already handle.","commonSituations":"Network interruption to the database, driver incompatibilities after an upgrade, out-of-memory in the worker, or unhandled edge cases in engine specs.","solutions":["Inspect the exception's __cause__ (or server logs — the original is logged) to find the real failure; the SqlLabException itself is just a wrapper","Fix the underlying cause: connectivity, driver version, SQL validity, or worker resources","If the cause is transient (connection blip), retrying the query after reconnecting is reasonable"],"exampleFix":"# inspecting the root cause of the catch-all\ntry:\n    ExecuteSqlCommand(...).run()\nexcept SqlLabException as ex:\n    root = ex.__cause__ or ex\n    logger.error(\"query failed: %s\", root)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    ExecuteSqlCommand(ctx).run()\nexcept SqlLabException as ex:\n    root = ex.__cause__ or ex\n    # branch on the ROOT cause (driver/network/OOM), not on SqlLabException itself\n    log_and_surface(root)","preventionTips":["Always inspect __cause__/server logs — SqlLabException is a wrapper, not the diagnosis","Keep database drivers and engine specs up to date to reduce unexpected exceptions"],"tags":["sql-lab","wrapper-exception","query-execution","catch-all"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}