Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
refactor(models): remove legacy db.session wrappers on Message accessors (#41886)
however-yir75f867da8552
diff --git a/api/core/ops/ops_trace_manager.py b/api/core/ops/ops_trace_manager.pyindex 3c109222f91..34679afc139 100644--- a/api/core/ops/ops_trace_manager.py+++ b/api/core/ops/ops_trace_manager.py@@ -1212,7 +1212,7 @@ class TraceTask:tool_parameters = {}created_time = message_data.created_atend_time = message_data.updated_at- agent_thoughts = message_data.agent_thoughts+ agent_thoughts = message_data.agent_thoughts_with_session(session=db.session())for agent_thought in agent_thoughts:if tool_name in agent_thought.tools:created_time = agent_thought.created_atdiff --git a/api/models/model.py b/api/models/model.pyindex f13fbf572df..ccd7f77d447 100644--- a/api/models/model.py+++ b/api/models/model.py@@ -1703,10 +1703,6 @@ class Message(Base):return re_sign_file_url_answer- @property- def user_feedback(self) -> MessageFeedback | None:- return self.user_feedback_with_session(session=db.session())-def user_feedback_with_session(self, *, session: Session) -> MessageFeedback | None:return session.scalar(select(MessageFeedback).where(MessageFeedback.message_id == self.id, MessageFeedback.from_source == "user")@@ -1720,24 +1716,12 @@ class Message(Base):select(MessageFeedback).where(MessageFeedback.message_id == self.id, MessageFeedback.from_source == "admin"))- @property- def feedbacks(self) -> Sequence[MessageFeedback]:- return self.feedbacks_with_session(session=db.session())-def feedbacks_with_session(self, *, session: Session) -> Sequence[MessageFeedback]:return session.scalars(select(MessageFeedback).where(MessageFeedback.message_id == self.id)).all()- @property- def annotation(self) -> MessageAnnotation | None:- return self.annotation_with_session(session=db.session())-def annotation_with_session(self, *, session: Session) -> MessageAnnotation | None:return session.scalar(select(MessageAnnotation).where(MessageAnnotation.message_id == self.id))- @property- def annotation_hit_history(self) -> MessageAnnotation | None:- return self.annotation_hit_history_with_session(session=db.session())-def annotation_hit_history_with_session(self, *, session: Session) -> MessageAnnotation | None:annotation_history = session.scalar(select(AppAnnotationHitHistory).where(AppAnnotationHitHistory.message_id == self.id)@@ -1748,10 +1732,6 @@ class Message(Base):)return None- @property- def app_model_config(self) -> AppModelConfig | None:- return self.app_model_config_with_session(session=db.session())-def app_model_config_with_session(self, *, session: Session) -> AppModelConfig | None:conversation = session.scalar(select(Conversation).where(Conversation.id == self.conversation_id))if conversation:@@ -1767,10 +1747,6 @@ class Message(Base):def message_metadata_dict(self) -> dict[str, Any]:return json.loads(self.message_metadata) if self.message_metadata else {}- @property- def agent_thoughts(self) -> Sequence[MessageAgentThought]:- return self.agent_thoughts_with_session(session=db.session())-def agent_thoughts_with_session(self, *, session: Session) -> Sequence[MessageAgentThought]:return session.scalars(select(MessageAgentThought)@@ -1782,10 +1758,6 @@ class Message(Base):def retriever_resources(self) -> Any:return self.message_metadata_dict.get("retriever_resources") if self.message_metadata else []- @property- def message_files(self) -> list[MessageFileInfo]:- return self.message_files_with_session(session=db.session())-def message_files_with_session(self, *, session: Session) -> list[MessageFileInfo]:from factories import file_factorydiff --git a/api/tests/unit_tests/core/ops/test_ops_trace_manager.py b/api/tests/unit_tests/core/ops/test_ops_trace_manager.pyindex f4bebc64c21..b37553f8510 100644--- a/api/tests/unit_tests/core/ops/test_ops_trace_manager.py+++ b/api/tests/unit_tests/core/ops/test_ops_trace_manager.py@@ -14,7 +14,7 @@ from uuid import UUIDimport pytestfrom flask import Flaskfrom sqlalchemy import Engine-from sqlalchemy.orm import Session, sessionmaker+from sqlalchemy.orm import Session, scoped_session, sessionmakerimport core.ops.ops_trace_manager as modulefrom core.ops.ops_trace_manager import OpsTraceManager, TraceQueueManager, TraceTask, TraceTaskName@@ -144,8 +144,9 @@ class RecordingDispatcher:@pytest.fixturedef database(sqlite_engine: Engine, sqlite_session: Session) -> Iterator[Session]:+ session_proxy = scoped_session(lambda: sqlite_session)with (- patch.object(module.db, "session", sqlite_session),+ patch.object(module.db, "session", session_proxy),patch.object(type(module.db), "engine", new_callable=PropertyMock, return_value=sqlite_engine),):yield sqlite_session@@ -289,7 +290,11 @@ def _message_data(**overrides):"inputs": "inputs",}data.update(overrides)- return SimpleNamespace(**data, to_dict=lambda: data)+ return SimpleNamespace(+ **data,+ agent_thoughts_with_session=lambda *, session: data["agent_thoughts"],+ to_dict=lambda: data,+ )def test_encrypt_decrypt_obfuscate_and_cache(