Repository navigation
Conversation
Supabase CLI generates TypedDicts that include datetime and UUID fields. These are valid serializable types (httpx handles them), but the narrow JSON type alias caused false type errors. Fixes supabase#1443.
Contributor
This is wrong, and this PR does not fix the underlying issue. |
spydon
added a commit
that referenced
this pull request
Nov 3, 2026
…d update (#1939) ## What Fixes #1443. SDK-831. `insert`, `upsert` and `update` were typed to take `JSON`, so the `Insert` and `Update` TypedDicts generated by `supabase gen types --lang python` failed type checking. This PR fixes both the types and the runtime serialization. ## Why the previous attempt was not enough PR #1514 added `datetime` and `UUID` to the `JSON` alias. That has two problems: 1. mypy (and pyright) treat a TypedDict as a `Mapping[str, object]` only, never as `Mapping[str, <recursive alias>]`, so even a widened `JSON` still rejects generated TypedDicts. I verified this against a CLI-style TypedDict. 2. The body was sent with httpx's `json=`, which uses `json.dumps`, so `datetime`, `UUID` and the other generated types raised `TypeError` at request time. ## Changes - New `RequestBody` type alias, `JSON | Mapping[str, object] | Sequence[Mapping[str, object]]`, used by `insert`, `upsert` and `update` (async and sync). It is a superset of the old `JSON` annotation, so existing callers keep type-checking. - Request bodies are now encoded by a private `_encode_json_body` helper in `base_request_builder` and sent as `content=`, keeping the same compact UTF-8 output httpx produced (`ensure_ascii=False`, `allow_nan=False`). On top of plain JSON it encodes every non-JSON type the generator emits: | Python type | Encoded as | | -------------------------- | ---------------------------------- | | `datetime.datetime`/`date` | ISO 8601 string | | `datetime.time` | ISO 8601 string | | `uuid.UUID` | canonical string | | `bytes` | `\x` hex string (PostgreSQL bytea) | Any other unsupported type still raises `TypeError`, as before. - `Content-Type: application/json` is set when a body is sent and the caller has not set one. - Bulk bodies passed as any sequence (for example a tuple) now get the `columns` query parameter, and any `Mapping` or `Sequence` is encoded, since `RequestBody` accepts them. ## Tests - Unit tests for `_encode_json_body` and `_is_row_list`: plain JSON output, every generated type, other mappings and sequences (tuples, `deque`, `MappingProxyType`, `UserDict`), unsupported types and NaN. - Client tests that pass CLI-style `PublicEventsInsert` / `PublicEventsUpdate` TypedDicts to `insert`, bulk `insert` (list and tuple), `upsert` and `update`, plus an `rpc` call with UUID and date params, and assert the encoded request body. Because mypy runs over `tests/`, these also act as type-level regression tests. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Insert, upsert, update, and RPC requests support a wider range of payloads, including typed mappings and sequences of rows. * JSON request bodies can include UUIDs, dates, times, and byte-like values, which are converted for transmission. * Bulk inserts accept tuples and other row sequences, with columns inferred from row records. * **Bug Fixes** * Custom content types are preserved, and select requests continue to send no body. * Unsupported values and non-finite numbers are rejected during JSON encoding. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
JSONtype alias inpostgrest/types.pydid not includedatetime,date,time, orUUID. The Supabase CLI generates TypedDicts thatuse these types, causing type errors when passing them to
.insert(),.upsert(), or.update().Fix
Added
datetime,date,time, andUUIDto theJSONtype alias.These types are already serializable by httpx/pydantic — this was purely
a type annotation gap.
Testing
All 43 existing sync unit tests pass.
Fixes #1443