Files
dify/api/services/conversation_variable_updater.py
d86435ee1e fix(workflow): coerce non-uuid variable ids and warn on skipped branches (#42750)
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Crazywoola <100913391+crazywoola@users.noreply.github.com>
2026-09-25 08:16:41 +00:00

30 lines
1.0 KiB
Python

from sqlalchemy import select
from sqlalchemy.orm import Session, sessionmaker
from graphon.variables.variables import VariableBase
from models import ConversationVariable
class ConversationVariableNotFoundError(Exception):
pass
class ConversationVariableUpdater:
def __init__(self, session_maker: sessionmaker[Session]) -> None:
self._session_maker: sessionmaker[Session] = session_maker
def update(self, conversation_id: str, variable: VariableBase) -> None:
stmt = select(ConversationVariable).where(
ConversationVariable.id == ConversationVariable.storage_id(variable),
ConversationVariable.conversation_id == conversation_id,
)
with self._session_maker() as session:
row = session.scalar(stmt)
if not row:
raise ConversationVariableNotFoundError("conversation variable not found in the database")
row.data = variable.model_dump_json()
session.commit()
def flush(self) -> None:
pass