From 970bbeca8d59252013f8357898b6bce4e7074ac0 Mon Sep 17 00:00:00 2001 From: Eddy ZHANG Date: Tue, 8 Sep 2026 07:26:20 +0000 Subject: [PATCH] refactor(models): remove the legacy db.session wrappers on App (#41942) --- api/models/model.py | 8 ----- .../unit_tests/models/test_app_models.py | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/api/models/model.py b/api/models/model.py index b735268065f..a9e0acd1f40 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -575,20 +575,12 @@ class App(Base): return True return False - @property - def mode_compatible_with_agent(self) -> str: - return self.mode_compatible_with_agent_with_session(session=db.session()) - def mode_compatible_with_agent_with_session(self, *, session: Session) -> str: if self.mode == AppMode.CHAT and self.is_agent_with_session(session=session): return AppMode.AGENT_CHAT return str(self.mode) - @property - def deleted_tools(self) -> list[DeletedToolInfo]: - return self.deleted_tools_with_session(session=db.session()) - def deleted_tools_with_session(self, *, session: Session) -> list[DeletedToolInfo]: from core.plugin.plugin_service import PluginService from core.tools.tool_manager import ToolManager, ToolProviderType diff --git a/api/tests/unit_tests/models/test_app_models.py b/api/tests/unit_tests/models/test_app_models.py index 7c7e2a8163d..9a48bf4a3d9 100644 --- a/api/tests/unit_tests/models/test_app_models.py +++ b/api/tests/unit_tests/models/test_app_models.py @@ -241,6 +241,35 @@ class TestAppModelValidation: # Assert assert result == AppMode.CHAT + @pytest.mark.parametrize("sqlite_session", [(App, AppModelConfig)], indirect=True) + def test_app_mode_compatible_with_agent_reports_agent_chat(self, sqlite_session: Session): + """A CHAT app whose own config enables agent mode reports AGENT_CHAT.""" + # Arrange + app = App( + tenant_id=str(uuid4()), + name="Test App", + mode=AppMode.CHAT, + enable_site=True, + enable_api=False, + created_by=str(uuid4()), + ) + sqlite_session.add(app) + sqlite_session.flush() + app.app_model_config_id = str(uuid4()) + config = AppModelConfig( + app_id=app.id, + agent_mode=json.dumps({"enabled": True, "strategy": "react"}), + ) + config.id = app.app_model_config_id + sqlite_session.add(config) + sqlite_session.flush() + + # Act + result = app.mode_compatible_with_agent_with_session(session=sqlite_session) + + # Assert + assert result == AppMode.AGENT_CHAT + @pytest.mark.parametrize("sqlite_session", [(App, AppModelConfig)], indirect=True) def test_deleted_tools_checks_plugin_builtin_providers_through_core_plugin_service(self, sqlite_session: Session): """Plugin-backed built-in tools are checked through core PluginService."""