fix: raise ResourceNotExistError in delete_sandbox when data plane returns "sandbox not found"#89
fix: raise ResourceNotExistError in delete_sandbox when data plane returns "sandbox not found"#89
Conversation
…ot found Agent-Logs-Url: https://github.com/Serverless-Devs/agentrun-sdk-python/sessions/82dd0492-f264-497a-9397-ffb5e79a1d90 Co-authored-by: OhYee <13498329+OhYee@users.noreply.github.com>
|
@copilot 修复方向正确(解决 issue #83 的 TERMINATED 残留场景),但建议对实现做一个关键调整。 问题:当前实现把 not-found 静默吞为成功if "sandbox not found" in message.lower():
return Sandbox.model_validate(
{"sandboxId": sandbox_id}, by_alias=True
)这有三个隐患:
建议:改抛
|
…ry tests Agent-Logs-Url: https://github.com/Serverless-Devs/agentrun-sdk-python/sessions/5b18eef6-655f-4a7b-be96-f7e39f852e04 Co-authored-by: OhYee <13498329+OhYee@users.noreply.github.com>
Done in eec1443. Changes made:
All 11 |
Control plane (
list_sandboxes) and data plane (delete_sandbox) can diverge: a TERMINATED sandbox remains visible in list results, but the data plane has already removed it, causingdelete_sandboxto raiseClientError('Failed to stop sandbox: sandbox not found')instead of a recognisable "not found" signal.Changes
agentrun/sandbox/client.py— In bothdelete_sandboxanddelete_sandbox_async, when the data plane returns a non-SUCCESS response with a message containing"sandbox not found", raiseResourceNotExistError("Sandbox", sandbox_id)instead ofClientError. This is consistent with the existing HTTP 404 path and avoids returning an incompleteSandboxobject. Updated docstrings document thatResourceNotExistErrorcovers both HTTP 404 and data-plane business-level not-found. A code comment tracks the long-term goal of switching to a stable server-sideerror_code(e.g.SandboxNotFound).tests/unittests/sandbox/test_client.py— Updated tests to assertResourceNotExistErroris raised for the data-plane not-found case; added boundary and negative tests: case-insensitive message variants, unrelated failure messages still raiseClientError, and empty message raisesClientError.Before / After