fix: update message update logic and add comment (#5295)

* refactor: Simplify message update logic in aupdate_messages function

* add comment
This commit is contained in:
anovazzi1 2024-12-16 17:05:54 -03:00 committed by GitHub
commit 4736aaed8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -135,10 +135,10 @@ async def aupdate_messages(messages: Message | list[Message]) -> list[Message]:
for message in messages:
msg = await session.get(MessageTable, message.id)
if msg:
if hasattr(message, "data"):
msg = msg.sqlmodel_update(message.data)
else:
msg = msg.sqlmodel_update(message.model_dump(exclude_unset=True, exclude_none=True))
msg = msg.sqlmodel_update(message.model_dump(exclude_unset=True, exclude_none=True))
# Convert flow_id to UUID if it's a string preventing error when saving to database
if msg.flow_id and isinstance(msg.flow_id, str):
msg.flow_id = UUID(msg.flow_id)
session.add(msg)
await session.commit()
await session.refresh(msg)