fix(agents): AgentRepository 空串 port 不再被拦截,修复服务端查不到/删不掉智能体
require_port 单角色后恒定 port='',但 AgentRepository 用 if not port 把空串当无 port 直接返回空/None,导致 GET /agents 永远为空、GET/DELETE 404 'Agent not found';本地删除依赖服务端先删身份,被 404 卡死后本地也无法删除。改为 if port is None 后空串正常参与查询。
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user