Repository navigation
fix(postgrest)!: return csv() results as a TextAPIResponse - #2051
Conversation
|
No actionable comments were generated in the recent review. Summary
Change: Bug fix Merge Risk:
|
csv() results get their own response type, TextAPIResponse, with the body as a str in data and the requested row count in count. rpc(...).csv() now returns the same TextRequestBuilder as csv() on a table instead of parsing the CSV body as JSON. SDK-1706
…turns a TextAPIResponse SDK-1706
604d8ec to
26685a4
Compare
…er (#2053) ## What `rpc(..., count=...)` without `head` is typed as `RPCFilterRequestBuilder`, so `rpc(..., count=...).csv()` type-checks. It also adds the integration and type-check coverage SDK-2975 asked for. #2051 already made `rpc().csv()` return a `TextRequestBuilder`. ## Changes - The `rpc()` overloads of `PostgrestClient` are reduced to the three `SupabaseClient` uses: `head=False` (the default) gives `RPCFilterRequestBuilder`, `head=True` gives `RPCCountRequestBuilder`, and a plain `bool` gives the union. Before, a call with only `count=` fell through to the catch-all overload and was typed as the union, which has no `csv()`. - New type-check fixture `tests/typecheck/rpc.py`, checked with mypy, pyright and pyrefly: `rpc(...).csv()` and its `TextAPIResponse` for both clients, `count=` with and without `head=True`, and the rejected chains after `csv()` and `csv()` on the count builder. - Integration tests in `tests/_async` and `tests/_sync` that call a function with `.csv()` against the local stack. Fixes SDK-2975
What
csv()results now have their own response type,TextAPIResponse, instead of being forced intoAPIResponse.data(typed as a list of rows) or returned as a barestr.TextAPIResponseholds the CSV body as astrindataand the row count incountwhen the query asked for one. It is exported frompostgrest.TextRequestBuilder.execute()returnsTextAPIResponse. Before, it returned a barestrand dropped the count fromContent-Range.rpc(...).csv()returns the sameTextRequestBuilderascsv()on a table. Since fix(postgrest)!: parse responses with json.loads and return scalar RPC results #2049 it returned the text inRPCResponse.data, typed asJSON. That special case inRPCFilterRequestBuilder.execute()is removed, and theRPCResponsedocstring andMIGRATION.mdnow point toTextAPIResponse.csv()moved fromBaseRPCRequestBuildertoRPCFilterRequestBuilder, andsdk-compliance.yamlnow lists the new symbols.APIErrorwith the response, like an invalid JSON body does.rpc()overloads now return the builderrpc()actually returns.count=..., head=TruereturnsRPCCountRequestBuilder(it claimedRPCFilterRequestBuilder), andcount=..., get=FalsereturnsRPCFilterRequestBuilder(it claimed a union withRPCCountRequestBuilder). Without this,.csv()after those calls would have been accepted by the type checker and failed at runtime, or rejected although it works.Breaking changes
.csv().execute()returnsTextAPIResponseinstead ofstr. Read the text fromresponse.data.strip_nulls()can no longer followrpc(...).csv(). They go beforecsv(), as they already did on a table.strip_nulls()aftercsv()already raisedValueError.MIGRATION.mdhas a new section with a type-checked example.Tests
tests/test_text_response.pycovers tablecsv()with a count, sync and async RPCcsv(), a non-UTF-8 body, and the correctedrpc()overload types (withassert_type) against a mock transport.TextAPIResponse.from_http_request_responseunit tests to the sync and async request builder tests.res.data.csv()thenstrip_nulls()test, since that chain no longer type-checks. ThePostgrestRequesttest still covers theValueError.Linear: SDK-1706