From b90ee8aabc77c7a1e37898d39b8310df9618dfe7 Mon Sep 17 00:00:00 2001 From: Pine Date: Fri, 4 Sep 2026 17:49:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(agents):=20AgentRepository=20=E7=A9=BA?= =?UTF-8?q?=E4=B8=B2=20port=20=E4=B8=8D=E5=86=8D=E8=A2=AB=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E6=9F=A5=E4=B8=8D=E5=88=B0/=E5=88=A0=E4=B8=8D=E6=8E=89?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit require_port 单角色后恒定 port='',但 AgentRepository 用 if not port 把空串当无 port 直接返回空/None,导致 GET /agents 永远为空、GET/DELETE 404 'Agent not found';本地删除依赖服务端先删身份,被 404 卡死后本地也无法删除。改为 if port is None 后空串正常参与查询。 --- app/infrastructure/repositories.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/infrastructure/repositories.py b/app/infrastructure/repositories.py index a023c68..22344f2 100644 --- a/app/infrastructure/repositories.py +++ b/app/infrastructure/repositories.py @@ -1065,21 +1065,21 @@ class AgentRepository: } async def get_by_user(self, user_id: str, port: str | None = None) -> list[dict]: - if not port: + if port is None: return [] stmt = select(Agent).where(Agent.user_id == user_id, Agent.port == port) rows = await self.session.scalars(stmt.order_by(Agent.created_at)) return [self._to_dict(a) for a in rows] async def get(self, agent_id: str, user_id: str, port: str | None = None) -> dict | None: - if not port: + if port is None: return None stmt = select(Agent).where(Agent.id == agent_id, Agent.user_id == user_id, Agent.port == port) a = await self.session.scalar(stmt) return self._to_dict(a) if a else None async def count_by_user(self, user_id: str, port: str | None = None) -> int: - if not port: + if port is None: return 0 stmt = select(Agent.id).where(Agent.user_id == user_id, Agent.port == port) return len(list(await self.session.scalars(stmt))) @@ -1114,7 +1114,7 @@ class AgentRepository: return self._to_dict(a) async def update(self, agent_id: str, user_id: str, fields: dict, port: str | None = None) -> dict | None: - if not port: + if port is None: return None stmt = select(Agent).where(Agent.id == agent_id, Agent.user_id == user_id, Agent.port == port) a = await self.session.scalar(stmt) @@ -1134,7 +1134,7 @@ class AgentRepository: return self._to_dict(a) async def delete(self, agent_id: str, user_id: str, port: str | None = None) -> bool: - if not port: + if port is None: return False stmt = select(Agent).where(Agent.id == agent_id, Agent.user_id == user_id, Agent.port == port) a = await self.session.scalar(stmt)