Repository navigation
fix(storage): exists reports invalid JWT or missing bucket as missing file - #2783
Conversation
…ng file Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Priority: ➖ Normal Change: Bug fix Merge Risk: ⚪ Minimal · up to
|
@supabase/auth-js
@supabase/functions-js
@supabase/postgrest-js
@supabase/realtime-js
@supabase/storage-js
@supabase/supabase-js
commit: |
…raise (#1825) **What kind of change does this PR introduce?** Bug fix. Closes #1821 **What is the current behavior?** `exists()` sends a HEAD request and returns `False` for any 400 or 404, so an invalid JWT or a missing bucket is reported as a missing file. **What is the new behavior?** `exists()` reads the object info, matching supabase/supabase-js#2783. It returns `False` only for a 404 `not_found` or a 404 without a parsable body, and raises `StorageApiError` for everything else (invalid JWT, missing bucket, other statuses). On `main`, `StorageApiError.code` comes from the body's `error` field, so the missing-object check uses `not_found` rather than `NoSuchKey`. Once the v3 error parsing (`code or error`) lands, this can check `NoSuchKey` the same way supabase-js does. Happy to port this to the v3 branch too. **Additional context** - Changed `_async/file_api.py`; `_sync/` matches the storage `build-sync` output plus ruff. - Replaced the two unit tests that asserted a bodiless 400 means "missing". Added sync and async tests mirroring the supabase-js cases: found, `NoSuchKey`, 404 without a code, bodiless 404, `InvalidJWT`, `NoSuchBucket`, bodiless 400 and 401. - `mypy src/storage3 tests` passes and `tests/test_client.py` passes (43 tests). I couldn't run the Docker-backed integration tests locally. @olirice @silentworks could you take a look when you have a moment? --------- Co-authored-by: Guilherme Souza <[email protected]>
🔍 Description
What changed?
StorageFileApi.exists()now reads the object info (GET /object/info/...) instead of sending aHEADrequest.{ data: true, error: null }when the object is found.{ data: false, error }only forNoSuchKey, or a 404 with no error code.InvalidJWT,NoSuchBucket, other 4xx/5xx, and network errors.throwOnError(), a missing object throws as before.existsdescribe these cases, and unit tests cover each one.Why was this change needed?
A
HEADresponse has no body, so the client could not tell an invalid or expired JWT (400) or a missing bucket (404) from a missing object.exists()treated every 400 and 404 as "file does not exist" and returnedfalse.This is consistent with changes made in Swift and Flutter: https://linear.app/supabase/issue/SDK-2286/drift-storagefile-bucketsfile-exists-js
🔄 Breaking changes
exists()previously returnedfalsefor any 400. It now throws for a 400 that is not a missing key, such asInvalidJWT. Callers that relied onfalsefor those cases now get the real error.📋 Checklist
<type>(<scope>): <description>pnpm nx formatto ensure consistent code formatting🤖 Generated with Claude Code