{"record":{"id":"8bd99ab089f9094f","repo":"apache/superset","slug":"unexpected-missing-key-id","errorCode":null,"errorMessage":"Unexpected missing key id","messagePattern":"Unexpected missing key id","errorType":"exception","errorClass":"SqlLabPermalinkCreateFailedError","httpStatus":500,"severity":"error","filePath":"superset/commands/sql_lab/permalink/create.py","lineNumber":58,"sourceCode":"\n    @transaction(\n        on_error=partial(\n            on_error,\n            catches=(\n                KeyValueCodecEncodeException,\n                KeyValueCreateFailedError,\n                SQLAlchemyError,\n            ),\n            reraise=SqlLabPermalinkCreateFailedError,\n        ),\n    )\n    def run(self) -> str:\n        self.validate()\n        entry = KeyValueDAO.create_entry(self.resource, self._properties, self.codec)\n        db.session.flush()\n        key = entry.id\n        if key is None:\n            raise SqlLabPermalinkCreateFailedError(\"Unexpected missing key id\")\n        return encode_permalink_key(key=key, salt=self.salt)\n\n    def validate(self) -> None:\n        pass\n","sourceCodeStart":40,"sourceCodeEnd":63,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/sql_lab/permalink/create.py#L40-L63","documentation":"CreateSqlLabPermalinkCommand.run() creates a key-value entry for the permalink, flushes the session, and reads entry.id. If the backend does not populate the primary key after flush (key is None), it raises SqlLabPermalinkCreateFailedError('Unexpected missing key id') (create.py:58). This is an integrity failure of the key-value persistence layer, not a user input error.","triggerScenarios":"POST /api/v1/sqllab/permalink/ where KeyValueDAO.create_entry succeeds at the Python level but the flushed KeyValueEntry row has no id — e.g. the key-value table schema is missing/drifted so the PK is not generated, or a DB backend that does not auto-populate the PK on flush.","commonSituations":"The metadata database schema is out of sync (migrations not run after upgrade) so the key_value_entry table lacks proper PK generation; an exotic metadata DB engine or a misconfigured custom KV backend; table corrupted or manually edited.","solutions":["Run Superset DB migrations ('superset db upgrade') to ensure the key-value tables match the expected schema","Inspect the key_value_entry table: confirm the primary key column exists, is non-null, and is auto-generated for your metadata engine","Check Superset logs for the underlying SQLAlchemy warnings during flush; fix any constraint/PK issues surfaced there","Retry the permalink creation once transient DB issues are ruled out"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    CreateSqlLabPermalinkCommand(...).run()\nexcept SqlLabPermalinkCreateFailedError:\n    # infrastructure issue: verify KV table schema, run migrations, then retry once\n    run_migrations_and_retry_once()","preventionTips":["Run 'superset db upgrade' as part of every deploy","Monitor for PK generation anomalies on key_value_entry after engine changes","Treat this error as a 500-class infra failure, not user error"],"tags":["permalink","key-value","database-migration","sql-lab"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}