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
Bulk inserts and upserts fail for valid column names containing a double quote or backslash. _unique_columns wraps raw keys in quotes, so PostgREST parses a different name and returns PGRST204.
What changed
Escape each generated column identifier before joining the list.
Preserve the existing outer quotes, de-duplication, empty-batch behavior, and JSON body.
Add async request-boundary tests and generated sync coverage for both write methods and list/tuple batches.
Scope
This covers automatically generated bulk column identifiers. Caller-supplied raw select and conflict syntax are outside the change.
Blast radius
Both clients use the same helper. Plain and comma-containing names retain their existing wire format; quoted and backslashed names now preserve their literal values.
Verification
The new public-client tests produced 24 failed, 16 passed before the fix and 40 passed after it. They check literal query values, unchanged JSON bodies, and returned data.
The complete PostgREST suite passed 813 tests against isolated PostgreSQL 17.11 and PostgREST 16.5, using the repository SQL fixtures. The original live single-row/batch reproduction also succeeds after the fix; before it, both special-name batches failed while escaped HTTP controls returned 201.
make postgrest.mypy, make postgrest.build-sync, Ruff lint/format checks, uv build --package postgrest, and git diff --check passed. Regeneration left no additional changes.
Local checks ran on Python 3.13. Hosted CI and the other supported Python/service versions remain separate validation.
Summary by CodeRabbit
Bug Fixes
Bulk inserts and upserts now correctly handle column names containing quotes or backslashes, while preserving the original column names and data.
No actionable comments were generated in the recent review.
Walkthrough
Bulk column serialization now escapes backslashes and double quotes in column names. New synchronous and asynchronous tests cover bulk inserts and upserts with list and tuple inputs.
_unique_columns escapes backslashes and double quotes before quoting column names. Tests check encoded column parameters, request bodies, and response data for inserts and upserts in both clients.
supabase/supabase-py#1939: It updates _unique_columns input handling and enables tuple row sequences, which the new tuple tests exercise.
Suggested reviewers:o-santi
Merge Risk: Minimal · up to 46fd2
No actionable merge-blocking issue is established for the bulk column escaping change. Merge after normal checks pass.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "fix(postgrest): escape quoted bulk column names" matches the main change. The raw summary and objectives both describe escaping backslashes and double quotes in the generated quoted column …
Linked Issues check
Directly linked issue #1944 is the only active target. Its coding requirement is to escape generated quoted column identifiers for bulk insert and upsert, for list and tuple inputs, in both clients. T…
Out of Scope Changes check
The whole-PR diff against the merge base c725015 contains three changed files, per the change summary. The first is the production helper change in base_request_builder.py, which directly implements #…
Full details: Title check
Explanation
The title "fix(postgrest): escape quoted bulk column names" matches the main change. The raw summary and objectives both describe escaping backslashes and double quotes in the generated quoted column names used by bulk insert and upsert in _unique_columns, with new tests for list and tuple inputs. The title is short, specific, and uses a conventional commit prefix that names the affected package.
Full details: Linked Issues check
Explanation
Directly linked issue #1944 is the only active target. Its coding requirement is to escape generated quoted column identifiers for bulk insert and upsert, for list and tuple inputs, in both clients. The reviewed head meets this requirement. In src/postgrest/src/postgrest/base_request_builder.py, _unique_columns now escapes each key by replacing \ with \, then " with ", before wrapping it in the existing outer double quotes and joining. This order is correct for the quoted-value syntax the issue cites. Both clients use this shared helper, so the sync client needs no separate production change. The added tests in src/postgrest/tests/_async/test_bulk_column_escaping.py and src/postgrest/tests/_sync/test_bulk_column_escaping.py are parametrized over insert and upsert, list and tuple inputs, and the names a"b, c\d, a"b, plain, and a,b. They assert the literal columns query value, the unchanged JSON body, and the returned data. I read the sync test and the helper diff directly. I did not read the async test file or the pre_insert and pre_upsert call sites directly. Those paths rely on the issue text and the PR summary, which state that both write paths use _unique_columns. The PR reports a passing live PostgREST suite, which I did not re-run. Caller-supplied raw select and conflict syntax is unchanged, as the issue requires.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against the merge base c725015 contains three changed files, per the change summary. The first is the production helper change in base_request_builder.py, which directly implements #1944. The second and third are the async and sync bulk column escaping test files. These tests cover the requirement, so they are in scope. The change does not touch select, conflict, or raw filter syntax. The change does not alter the JSON body, empty-batch handling, or de-duplication. The str(key) call only affects non-string keys, which the existing behavior already covers. I found no unrelated change in the evidence I reviewed. I did not run a full file-level whole-PR diff, so this verdict relies on the change summary for files other than the helper.
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 3 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Tip
🎯 Customize your risk assessments
Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.
✅ Automatic approvals, with your rules
Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.
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; 7 remain after this review.
…1948)
## Why
Closes#1944. Alternative to #1947.
Bulk inserts and upserts send the row keys in the `columns` query
parameter, wrapped in double quotes but not escaped. A column name
containing `"` or `\` is then parsed as a different name by PostgREST,
which responds with `PGRST204`.
## What changed
- Extract the existing quote and escape logic from `sanitize_param` and
`sanitize_array_element` into a single `quote` helper in `utils.py`.
- Use `quote` in `_unique_columns`, so bulk column names get the same
escaping as filter values and array elements.
- Plain and comma-containing names keep their current wire format
(`"plain"`, `"a,b"`).
## Tests
- `test_quote` unit tests the helper directly.
- `test_bulk_write_columns` (async and generated sync) gains cases for
names containing a comma, a double quote, a backslash, and both.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved handling of column names and values containing commas,
quotation marks, or backslashes when requests are built. These
characters are now quoted and escaped consistently, reducing malformed
requests in bulk writes and parameter values across synchronous and
asynchronous operations.
<!-- 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
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.
Why
Closes #1944.
Bulk inserts and upserts fail for valid column names containing a double quote or backslash.
_unique_columnswraps raw keys in quotes, so PostgREST parses a different name and returnsPGRST204.What changed
Scope
This covers automatically generated bulk column identifiers. Caller-supplied raw select and conflict syntax are outside the change.
Blast radius
Both clients use the same helper. Plain and comma-containing names retain their existing wire format; quoted and backslashed names now preserve their literal values.
Verification
24 failed, 16 passedbefore the fix and40 passedafter it. They check literal query values, unchanged JSON bodies, and returned data.make postgrest.mypy,make postgrest.build-sync, Ruff lint/format checks,uv build --package postgrest, andgit diff --checkpassed. Regeneration left no additional changes.Local checks ran on Python 3.13. Hosted CI and the other supported Python/service versions remain separate validation.
Summary by CodeRabbit