fix: make user_id variable valid and fix type signature in messages endpoints (#5236)
* fix: enhance user_id validation in CustomComponent to ensure correct UUID handling * Added type checks for user_id to ensure it is either a string or a UUID before conversion. * Improved error handling by raising TypeError for invalid user_id types. * fix: update flow_id and session_id types to UUID in monitor endpoint * fix: convert flow_id to UUID type before adding messages * fix: convert flow_id string to UUID when storing message * fix: update session_id type to string in get_messages endpoint for improved type consistency
This commit is contained in:
parent
fc4d93a33d
commit
2c0991f9cf
4 changed files with 12 additions and 3 deletions
|
|
@ -40,7 +40,7 @@ async def delete_vertex_builds(flow_id: Annotated[UUID, Query()], session: DbSes
|
|||
@router.get("/messages")
|
||||
async def get_messages(
|
||||
session: DbSession,
|
||||
flow_id: Annotated[str | None, Query()] = None,
|
||||
flow_id: Annotated[UUID | None, Query()] = None,
|
||||
session_id: Annotated[str | None, Query()] = None,
|
||||
sender: Annotated[str | None, Query()] = None,
|
||||
sender_name: Annotated[str | None, Query()] = None,
|
||||
|
|
|
|||
|
|
@ -1011,6 +1011,8 @@ class Component(CustomComponent):
|
|||
UUID(self.graph.session_id) if isinstance(self.graph.session_id, str) else self.graph.session_id
|
||||
)
|
||||
message.session_id = session_id
|
||||
if hasattr(message, "flow_id") and isinstance(message.flow_id, str):
|
||||
message.flow_id = UUID(message.flow_id)
|
||||
stored_message = await self._store_message(message)
|
||||
|
||||
self._stored_message_id = stored_message.id
|
||||
|
|
|
|||
|
|
@ -440,9 +440,14 @@ class CustomComponent(BaseComponent):
|
|||
raise ValueError(msg)
|
||||
variable_service = get_variable_service() # Get service instance
|
||||
# Retrieve and decrypt the variable by name for the current user
|
||||
if isinstance(self.user_id, str):
|
||||
user_id = uuid.UUID(self.user_id)
|
||||
elif isinstance(self.user_id, uuid.UUID):
|
||||
user_id = self.user_id
|
||||
else:
|
||||
msg = f"Invalid user id: {self.user_id}"
|
||||
raise TypeError(msg)
|
||||
async with async_session_scope() as session:
|
||||
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):
|
||||
|
|
|
|||
|
|
@ -343,6 +343,8 @@ async def astore_message(
|
|||
raise ValueError(msg)
|
||||
if hasattr(message, "id") and message.id:
|
||||
return await aupdate_messages([message])
|
||||
if flow_id and not isinstance(flow_id, UUID):
|
||||
flow_id = UUID(flow_id)
|
||||
return await aadd_messages([message], flow_id=flow_id)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue