{"record":{"id":"70eddc6d91f8ca88","repo":"apache/superset","slug":"an-error-occurred-while-updating-the-value-70eddc","errorCode":null,"errorMessage":"An error occurred while updating the value.","messagePattern":"An error occurred while updating the value\\.","errorType":"exception","errorClass":"KeyValueUpdateFailedError","httpStatus":500,"severity":"error","filePath":"superset/daos/key_value.py","lineNumber":177,"sourceCode":"    def update_entry(\n        resource: KeyValueResource,\n        value: Any,\n        codec: KeyValueCodec,\n        key: Key,\n        expires_on: datetime | None = None,\n    ) -> KeyValueEntry:\n        \"\"\"\n        Update an existing entry, raising ``KeyValueUpdateFailedError`` if no entry\n        exists for the given key.\n        \"\"\"\n        if entry := KeyValueDAO.get_entry(resource, key):\n            entry.value = codec.encode(value)\n            entry.expires_on = expires_on\n            entry.changed_on = datetime.now()\n            entry.changed_by_fk = get_user_id()\n            return entry\n\n        raise KeyValueUpdateFailedError()\n","sourceCodeStart":159,"sourceCodeEnd":178,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/daos/key_value.py#L159-L178","documentation":"Raised by KeyValueDAO.update_entry when KeyValueDAO.get_entry(resource, key) returns no row, meaning there is no existing KeyValueEntry to mutate. Update is deliberately strict: unlike upsert_entry, it never creates the missing entry. The error class derives from UpdateFailedError and maps to a generic 'update failed' HTTP response, so the real signal is that the key does not exist under that resource.","triggerScenarios":"Calling update_entry with a key that was never created or has been deleted; updating an expired entry that a prior purge removed; using the right key under the wrong KeyValueResource enum value (resources partition the namespace); a UUID vs int key mismatch with how the entry was created.","commonSituations":"Two-step flows where the client 'updates' a tab/dashboard state before the initial create succeeds; background workers racing with expiration cleanup; environment resets (metadata DB wiped) while browsers hold old keys in local state.","solutions":["Ensure create_entry (or upsert_entry) ran successfully for that exact resource+key before calling update_entry.","If create-or-update semantics are intended, call upsert_entry instead of update_entry.","Double-check the KeyValueResource enum value matches the one used on creation.","Catch the error and fall back to create_entry when the entry is genuinely absent."],"exampleFix":"# before\nKeyValueDAO.update_entry(resource, value, codec, key=entry_key)  # entry missing -> KeyValueUpdateFailedError\n\n# after\nfrom superset.daos.key_value import KeyValueDAO\nfrom superset.key_value.commands.exceptions import KeyValueUpdateFailedError\ntry:\n    KeyValueDAO.update_entry(resource, value, codec, key=entry_key)\nexcept KeyValueUpdateFailedError:\n    KeyValueDAO.create_entry(resource, value, codec, key=entry_key)  # or upsert_entry","handlingStrategy":"try-catch","validationCode":"# prefer get_entry existence check, or just use upsert semantics\nentry = KeyValueDAO.get_entry(resource, key)\nif entry is None:\n    KeyValueDAO.create_entry(resource, value, codec, key=key)\nelse:\n    KeyValueDAO.update_entry(resource, value, codec, key=key)","typeGuard":null,"tryCatchPattern":"from superset.key_value.commands.exceptions import KeyValueUpdateFailedError\ntry:\n    KeyValueDAO.update_entry(resource, value, codec, key=key)\nexcept KeyValueUpdateFailedError:\n    KeyValueDAO.create_entry(resource, value, codec, key=key)  # entry absent -> create","preventionTips":["Use upsert_entry when create-or-update semantics are acceptable.","Ensure the create step of a flow commits before issuing updates.","Keep the KeyValueResource enum value consistent between create and update call sites."],"tags":["key-value","dao","not-found","update"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}