fix: fail delete_collection clearly in cloud mode — the API has no folder deletion

The server exposes only POST /folder and GET /folders (verified against the
full route table and its git history — a DELETE /folder route never
existed; the 0.2.x SDK accordingly shipped create_folder/list_folders but
no delete). The DELETE /folder/{id}/ call could only 404, surfacing as a
misleading 'Not Found' CloudAPIError while leaving the stale folder id in
the cache. Raise a clear not-supported error pointing at the dashboard;
keep the idempotent no-op for missing collections and folderless plans.
This commit is contained in:
Ray 2026-07-22 12:29:57 +08:00
parent b8c63eba86
commit 225dcc31b4

View file

@ -205,13 +205,14 @@ class CloudBackend:
except CollectionNotFoundError:
return # already gone — delete is idempotent
if folder_id:
self._request("DELETE", f"/folder/{self._enc(folder_id)}/")
# Drop the cached id so a later same-name op re-resolves instead of
# reusing the now-deleted folder_id. Only when it was a REAL id —
# if folder_id was falsy, the cache holds the "folders unavailable
# on this plan" None sentinel, which must survive so we don't
# re-issue a doomed GET /folders/ on the next call.
self._folder_id_cache.pop(name, None)
# The cloud API has no folder-deletion endpoint (only POST /folder
# and GET /folders exist) — fail clearly instead of issuing a
# request that can only 404.
raise PageIndexError(
f"Deleting a cloud collection is not supported by the PageIndex "
f"API — delete folder '{name}' in the dashboard "
"(https://dash.pageindex.ai) instead."
)
# ── Document management ───────────────────────────────────────────────