Fix: Handle optional api_key_id in Redis instance deletion#46
Closed
ttien0181 wants to merge 1 commit intoAI-Decenter:mainfrom
Closed
Fix: Handle optional api_key_id in Redis instance deletion#46ttien0181 wants to merge 1 commit intoAI-Decenter:mainfrom
ttien0181 wants to merge 1 commit intoAI-Decenter:mainfrom
Conversation
This commit fixes a database decoding error during the Redis instance deletion process. The `try_get` call in `delete_redis_instance` failed when the `api_key_id` column was `NULL` in the database. The fix involves changing the `api_key_id` variable to `Option<Uuid>` and wrapping the API key deactivation logic in a conditional block to handle cases where the key does not exist. This ensures that instances without an associated API key can be deleted successfully.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
This pull request resolves a database error encountered when deleting a Redis instance that does not have an associated API key. The API would previously return the error:
Database field error: error occurred while decoding column "api_key_id": unexpected null; try decoding as an 'Option'.Root Cause
In the
delete_redis_instancehandler withinredis_instances.rs, the code attempted to extract the value ofapi_key_idand directly cast it toUuid, a type that does not permitNULLvalues. While theRedisInstancestruct was correctly defined to handle anOption<Uuid>, thesqlx::querycombined withtry_getbypassed this optionality check, leading to the decoding error when aNULLvalue was encountered in the database.Solution
api_key_idvariable is now declared asOption<Uuid>to correctly handle the optional nature of the database field.if letstatement has been added to conditionally execute theUPDATEquery on theapi_keystable only when anapi_key_idis present (is not None).This change ensures a robust and reliable deletion process, preventing crashes for instances with no API key linked.