refactor(models): remove the legacy db.session wrappers on App (#41942)

This commit is contained in:
Eddy ZHANG 2026-09-08 07:26:20 +00:00 committed by GitHub
parent 8acdb1538b
commit 970bbeca8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 8 deletions

View File

@ -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

View File

@ -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."""