Skip to content

Fix: Handle optional api_key_id in Redis instance deletion#46

Closed
ttien0181 wants to merge 1 commit intoAI-Decenter:mainfrom
ttien0181:feature/gateway
Closed

Fix: Handle optional api_key_id in Redis instance deletion#46
ttien0181 wants to merge 1 commit intoAI-Decenter:mainfrom
ttien0181:feature/gateway

Conversation

@ttien0181
Copy link
Contributor

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_instance handler within redis_instances.rs, the code attempted to extract the value of api_key_id and directly cast it to Uuid, a type that does not permit NULL values. While the RedisInstance struct was correctly defined to handle an Option<Uuid>, the sqlx::query combined with try_get bypassed this optionality check, leading to the decoding error when a NULL value was encountered in the database.

Solution

  • Update Data Type: The api_key_id variable is now declared as Option<Uuid> to correctly handle the optional nature of the database field.
  • Implement Null-Safety: An if let statement has been added to conditionally execute the UPDATE query on the api_keys table only when an api_key_id is present (is not None).

This change ensures a robust and reliable deletion process, preventing crashes for instances with no API key linked.

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.
@ngocbd ngocbd closed this Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants