You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(postgrest): accept generated TypedDict types in insert, upsert and update - #2062
insert and upsert take a RequestBody (Mapping[str, object] | Sequence[Mapping[str, object]]) and update a Mapping[str, object], so the Insert and Update TypedDicts of supabase gen types --lang python type-check without casts.
Both builders serialize bodies through the shared _rows_payload and _row_payload helpers, which now send bytes as the \x hex text PostgreSQL reads for bytea, also inside models and dataclasses, and raise TypeError for a body that is not a row or rows.
Adds a files table to the test stack and round-trip integration tests for bytea, uuid, timestamptz and date columns.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 59e09153-5ffb-4a2d-9a73-ea8a3f7c8405
Commits
Reviewing files that changed from the base of the PR and between ffe4f40 and 96f241e.
Files selected for processing: 7
src/postgrest/src/postgrest/request_builder.py
src/postgrest/src/postgrest/typed_builder.py
src/postgrest/src/postgrest/types.py
src/postgrest/src/postgrest/utils.py
src/postgrest/tests/test_typed_builder.py
src/postgrest/tests/test_write_bodies.py
src/postgrest/tests/typecheck/queries.py
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
New Features
Insert, update, and upsert requests now support typed row mappings and collections of rows, including values such as UUIDs, dates, and timestamps.
Binary values are serialized for PostgreSQL bytea fields, and serialization failures return clear type errors.
Documentation
Expanded guidance on accepted write payloads and how binary values are sent.
The write methods insert, upsert, and update now accept JSON values, mappings, and sequences of mappings as request bodies. A shared serializer converts supported values to JSON-compatible data and encodes bytes-like values as PostgreSQL bytea hex text. The methods pass serialized bodies to mutation preparation and raise TypeError when serialization fails. Tests cover request encoding, type checking, and synchronous and asynchronous writes using a new public.files table.
Sequence Diagram(s)
sequenceDiagram
participant Request as RequestBuilder.insert/upsert/update
participant Body as RequestBuilder._body
participant Serializer as utils._jsonable
participant Prepare as pre_insert/pre_upsert/pre_update
Request->>Body: Pass RequestBody
Body->>Serializer: Convert payload to JSON-compatible data
Serializer-->>Body: Return JSON data
Body-->>Request: Return serialized body
Request->>Prepare: Pass serialized body
Loading
Possibly related PRs
supabase/supabase-py#1939: Adds the same request-body type and bytes-to-bytea serialization pattern for write methods.
Change: Bug fix
Merge Risk: Minimal · previous review ffe4f
Write methods now accept generated TypedDict bodies and serialize bytes for PostgreSQL bytea. No concrete merge-blocking risk was found in the supplied change.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.
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
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.
Ports the v2 fix (#1939) to v3. SDK-2825
insertandupserttake aRequestBody(Mapping[str, object] | Sequence[Mapping[str, object]]) andupdateaMapping[str, object], so theInsertandUpdateTypedDicts ofsupabase gen types --lang pythontype-check without casts._rows_payloadand_row_payloadhelpers, which now sendbytesas the\xhex text PostgreSQL reads forbytea, also inside models and dataclasses, and raiseTypeErrorfor a body that is not a row or rows.filestable to the test stack and round-trip integration tests forbytea,uuid,timestamptzanddatecolumns.