Skip to content

fix(postgrest): accept generated TypedDict types in insert, upsert and update - #2062

Merged
spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2825-postgrest-accept-generated-typeddict
Nov 16, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2825-postgrest-accept-generated-typeddict

Conversation

@spydon

@spydon spydon commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Ports the v2 fix (#1939) to v3. SDK-2825

  • 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.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • 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

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7c48f3f8-6522-4523-a97c-baa67191b4a1
Commits

Reviewing files that changed from the base of the PR and between 16825e8 and ffe4f40.

Files selected for processing: 10

  • src/postgrest/infra/supabase/migrations/20240104000000_write_bodies.sql
  • 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/_async/test_filter_request_builder_integration.py
  • src/postgrest/tests/_sync/test_filter_request_builder_integration.py
  • src/postgrest/tests/test_typed_builder.py
  • src/postgrest/tests/test_write_bodies.py
  • src/postgrest/tests/typecheck/queries.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

@spydon
spydon merged commit 439735e into main Nov 16, 2026
28 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2825-postgrest-accept-generated-typeddict branch November 16, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant