Skip to content

fix(postgrest)!: send datetime filter values as iso 8601 with an offset - #2047

Merged
spydon merged 3 commits into
mainfrom
lukasklingsbo/sdk-2760-postgrest-serialize-datetime-filter
Nov 13, 2026
Merged

spydon merged 3 commits into
mainfrom
lukasklingsbo/sdk-2760-postgrest-serialize-datetime-filter

Conversation

@spydon

@spydon spydon commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Filter values went through str(), so a datetime was sent as 2024-01-01 12:00:00, with a space and, for a naive value, no offset. PostgREST then read the time in the database time zone, which can shift results by hours.

  • _serialize_filter_value renders a datetime as ISO 8601 with its UTC offset. An aware datetime keeps its offset. A naive datetime is taken as UTC. This matches supabase-swift, which sends dates in UTC and reads timestamps without an offset as UTC, and the old behavior on Supabase, where the database runs in UTC. It also works for datetime.min and datetime.max.
  • The string builder in_(), array literal members (cs(), cd(), contains(), contained_by(), overlaps()) and RPC query arguments now use the same serialization, so the same value is rendered the same way everywhere. For array members, this also renders booleans as true/false and dicts and lists as compact JSON.
  • _rpc_query_param delegates to _serialize_filter_value instead of duplicating its boolean and dict branches, and the typed filter no longer serializes array members twice.
  • date and time values are unchanged, since str() already gives ISO 8601 for them.
  • MIGRATION.md documents the change and the rule for naive values.

Tests

  • Unit tests for aware, naive, date and time values, datetime.min and datetime.max, array elements, in_(), RPC query arguments, and the typed filter rendering at top level and inside an or group.
  • Range rendering tests updated to the T separator.

Closes SDK-2760

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Datetime filters now use ISO 8601 formatting with timezone offsets. Naive datetimes are interpreted as local time, and datetime values in arrays follow the same serialization rules.
  • Documentation
    • Clarified datetime filter formatting and noted that date and time serialization is unchanged.

Datetime filter values now use ISO 8601 serialization. Aware datetimes retain their offset, and naive datetimes are converted to local time before serialization. Array elements use the same filter serializer. Tests cover comparison filters, OR groups, range values, and array elements. The migration guide documents the datetime behavior and states that date and time serialization is unchanged.

Change: Bug fix

Merge Risk: Minimal · up to 51714

Datetime filter values now use ISO 8601 with an offset, and naive datetimes are treated as UTC. The change is tested and documented, and no actionable merge-blocking risk is evident.

- [ ] 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: 0cbbd962-4ba1-4cd8-8078-282d1be657f6
Commits

Reviewing files that changed from the base of the PR and between 0b0ae8c and 5171485.

Files selected for processing: 2

  • src/postgrest/src/postgrest/utils.py
  • src/postgrest/tests/test_utils.py

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

@spydon
spydon merged commit 8b1ab30 into main Nov 13, 2026
26 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2760-postgrest-serialize-datetime-filter branch November 13, 2026 13:11
spydon added a commit that referenced this pull request Nov 13, 2026
)

Ports the bulk column name fix from v2 (#1948) to v3, and makes `in_()`
reject `None`.

## Changes

- **Bulk column names are escaped.** `_unique_columns` built the
`columns=` parameter for bulk inserts and upserts by wrapping each key
in double quotes without escaping. A key such as `a"b` could break out
of the quotes and add other columns. Keys now go through `_quote`, which
escapes `\` and `"` the same way filter values are quoted.
- **`in_()` rejects `None`.** PostgREST quotes every member of an `in`
list (`pgBuildArrayLiteral`), so `null` there is the text `'null'`,
never SQL `NULL`. It matched the literal string on text columns and
failed to parse on others. Both the builder `in_()` and the typed
`Column.in_()` now raise a `ValueError` pointing to `is_()`. This
differs from v2 #1863, which sends `null`.

Serializing booleans in `in_()` as `true`/`false`, the other half of the
ticket, landed on main with #2047.

## Tests

- `test_unique_columns.py`: keys containing `"` and `\` are escaped.
- `test_in_filter.py`: `[True, False]` renders as `in.(true,false)` for
the sync and async clients, and `None` raises.
- `test_filter.py`: the typed `Column.in_([None])` raises.

SDK-2816
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