fix: improve UUID handling in custom component variables (#5230)

* 🐛 (custom_component.py): fix user_id assignment to convert it to UUID type for consistency and correctness

* [autofix.ci] apply automated fixes

* 🐛 (custom_component.py): fix potential bug by checking if self.user_id is a string before converting it to UUID

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Cristhian Zanforlin Lousa 2024-12-12 12:13:38 -03:00 committed by GitHub
commit 2e7a5cdd67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
from __future__ import annotations
import asyncio
import uuid
from collections.abc import Callable, Sequence
from pathlib import Path
from typing import TYPE_CHECKING, Any, ClassVar
@ -439,7 +440,8 @@ class CustomComponent(BaseComponent):
variable_service = get_variable_service() # Get service instance
# Retrieve and decrypt the variable by name for the current user
async with async_session_scope() as session:
user_id = self.user_id or ""
if isinstance(self.user_id, str):
user_id = uuid.UUID(self.user_id)
return await variable_service.get_variable(user_id=user_id, name=name, field=field, session=session)
async def list_key_names(self):