{"record":{"id":"8c1acb9515478503","repo":"apache/superset","slug":"generic-db-engine-error","errorCode":"GENERIC_DB_ENGINE_ERROR","errorMessage":"Failed to execute %(query)s: The query record was not created as expected Please contact an administrator for further assistance or try again.","messagePattern":"Failed to execute (.+?): The query record was not created as expected Please contact an administrator for further assistance or try again\\.","errorType":"exception","errorClass":"SqlLabException","httpStatus":500,"severity":"error","filePath":"superset/commands/sql_lab/execute.py","lineNumber":197,"sourceCode":"\n    def _save_new_query(self, query: Query) -> None:\n        \"\"\"\n        Saves the new SQL Lab query.\n\n        Committing within a transaction violates the \"unit of work\" construct, but is\n        necessary for async querying. The Celery task is defined within the confines\n        of another command and needs to read a previously committed state given the\n        `READ COMMITTED` isolation level.\n\n        To mitigate said issue, ideally there would be a command to prepare said query\n        and another to execute it, either in a sync or async manner.\n\n        :param query: The SQL Lab query\n        \"\"\"\n        try:\n            self._query_dao.create(query)\n        except SQLAlchemyError as ex:\n            raise SqlLabException(\n                self._execution_context,\n                SupersetErrorType.GENERIC_DB_ENGINE_ERROR,\n                \"The query record was not created as expected\",\n                ex,\n                \"Please contact an administrator for further assistance or try again.\",\n            ) from ex\n\n        db.session.commit()  # pylint: disable=consider-using-transaction\n\n    def _validate_access(\n        self, query: Query, template_params: Optional[dict[str, Any]] = None\n    ) -> None:\n        try:\n            self._access_validator.validate(query, template_params)\n        except Exception as ex:\n            raise QueryIsForbiddenToAccessException(self._execution_context, ex) from ex\n\n    def _set_query_limit_if_required(","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/sql_lab/execute.py#L179-L215","documentation":"Raised in ExecuteSqlCommand._save_new_query (superset/commands/sql_lab/execute.py:197) as SqlLabException with SupersetErrorType.GENERIC_DB_ENGINE_ERROR when self._query_dao.create(query) throws a SQLAlchemyError. The Query record that SQL Lab persists before dispatching work could not be written to Superset's metadata database; the original SQLAlchemyError is chained. The subsequent db.session.commit() is the deliberate early commit that makes async Celery execution possible.","triggerScenarios":"Any metadata-DB write failure at query creation: schema drift (Query table migration not applied), constraint violation on the query row (e.g. duplicate client_id), metadata database down/restarted, or connection pool exhaustion at high concurrency.","commonSituations":"Upgrading Superset without running `superset db upgrade` so the query table schema mismatches; Postgres/MySQL metadata DB briefly unavailable; unique-constraint races on client_id from double-submitted queries.","solutions":["Check the chained SQLAlchemyError and Superset server logs to identify the exact metadata-DB failure","If schema-related, run `superset db upgrade` so the Query model matches the database","Verify metadata DB connectivity/health and connection pool sizing under load","For duplicate client_id races, generate a fresh client_id per submission instead of reusing one"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    ExecuteSqlCommand(ctx).run()\nexcept SqlLabException as ex:\n    if ex.error_type == SupersetErrorType.GENERIC_DB_ENGINE_ERROR and \"query record was not created\" in str(ex):\n        root = ex.__cause__  # SQLAlchemyError from metadata DB\n        # schema drift? run `superset db upgrade`; db down? check metadata DB health\n        ","preventionTips":["Run `superset db upgrade` after every version bump before accepting queries","Monitor metadata-DB connectivity and pool saturation under concurrent SQL Lab load","Generate a fresh client_id per submission to avoid unique-constraint races"],"tags":["sql-lab","metadata-db","sqlalchemy","query-execution","persistence"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}