Repository navigation
fix(postgrest)!: send datetime filter values as iso 8601 with an offset - #2047
Conversation
|
No actionable comments were generated in the recent review. Summary
Change: Bug fix Merge Risk:
|
) 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
Summary
Filter values went through
str(), so adatetimewas sent as2024-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_valuerenders adatetimeas ISO 8601 with its UTC offset. An awaredatetimekeeps its offset. A naivedatetimeis 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 fordatetime.minanddatetime.max.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 astrue/falseand dicts and lists as compact JSON._rpc_query_paramdelegates to_serialize_filter_valueinstead of duplicating its boolean and dict branches, and the typed filter no longer serializes array members twice.dateandtimevalues are unchanged, sincestr()already gives ISO 8601 for them.MIGRATION.mddocuments the change and the rule for naive values.Tests
dateandtimevalues,datetime.minanddatetime.max, array elements,in_(), RPC query arguments, and the typed filter rendering at top level and inside anorgroup.Tseparator.Closes SDK-2760