Skip to content

fix(postgrest): serialize dictionary rpc query arguments as json - #1848

Closed
Kayvan-Zahiri wants to merge 1 commit into
supabase:mainfrom
Kayvan-Zahiri:codex/serialize-rpc-json-arguments
Closed

Kayvan-Zahiri wants to merge 1 commit into
supabase:mainfrom
Kayvan-Zahiri:codex/serialize-rpc-json-arguments

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix for PostgREST GET/HEAD RPC dictionary arguments.

What is the current behavior?

Closes #1847, filed before implementation as CONTRIBUTING.md requests.

rpc("example", {"options": {"enabled": True}}, get=True) sends options={'enabled': True}: HTTPX stringifies the dictionary as Python text, which is invalid for a named PostgreSQL JSON/JSONB argument. HEAD has the same behavior. POST already serializes the argument correctly in its JSON body.

What is the new behavior?

JSON-encode dictionaries in the shared RPC query-argument helper. Preserve the existing list/tuple PostgreSQL array-literal handling and leave raw JSON strings and other scalar arguments unchanged. No public symbols, dependencies or versions change.

The async-source request-level tests cover GET, HEAD and POST with a boolean dictionary, nested arrays/nulls and an empty dictionary. They also check pre-serialized JSON strings, array arguments and ordinary strings. Sync tests are regenerated with make postgrest.build-sync, followed by make ruff as AGENTS.md requires. Four async regression cases fail before the fix; five controls pass.

Additional context

Validation with Python 3.12.12 and the unchanged frozen uv workspace:

  • 398 offline PostgREST tests pass, including both sync and async coverage.
  • Package mypy: no issues in 32 source files.
  • Workspace make ruff and git diff --check: pass.

The offline run explicitly excludes the two database integration test files; full Docker/PostgREST integration, other workspace packages and the Python3.9–3.14/OS matrix were not run. New HTTP requests use MockTransport; no credentials or hosted calls were used. GNU sed was installed for the prescribed generator. Release-managed versions, changelogs and lockfile are unchanged. Developed with Codex assistance and reproduced locally.

@Kayvan-Zahiri

Copy link
Copy Markdown
Contributor Author

@olirice @silentworks — requesting review as CONTRIBUTING.md asks. This small fix follows issue #1847 and adds generated sync/async request-level coverage; 398 offline PostgREST tests and package mypy pass. Database integration tests have not been run.

spydon added a commit that referenced this pull request Nov 2, 2026
…requests (#1899)

## What

`rpc(..., get=True)` and `rpc(..., head=True)` send arguments in the
query string. Dictionary arguments were passed through as-is, so httpx
rendered them with Python's `str(dict)` (for example `{'enabled':
True}`), which PostgREST cannot parse as `json`/`jsonb`.

`rpc_query_param` now encodes dictionaries as compact JSON
(`json.dumps(value, separators=(",", ":"))`). POST requests are
unchanged, since their arguments are already sent as a JSON body.

## Tests

Added `test_rpc_serializes_dictionary_arguments` (async and generated
sync) using `MockTransport`. It checks GET, HEAD and POST with flat,
nested and empty dictionaries, and verifies that string, list and scalar
arguments keep their existing encoding.

## Credit

Based on #1848 by Kayvan-Zahiri, brought onto current main and switched
to compact JSON. This PR supersedes #1848.

Closes #1847
Linear: SDK-2640

Co-authored-by: Kayvan Zahiri <[email protected]>
@spydon

spydon commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix! This has been superseded by #1899, which builds on your changes (with you credited as co-author) and is now merged.

@spydon spydon closed this Nov 3, 2026
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.

PostgREST GET and HEAD RPC calls stringify dictionary arguments as Python instead of JSON

2 participants