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
{{ message }}
Repository navigation
fix(realtime): port the v2 postgres_changes fixes - #2052
Ports three postgres_changes fixes from v2 to v3. Fixes SDK-2827.
Default schema
PostgresChangesBinding.schema and RealtimeChannelOptions.postgres_changes(schema=...) now default to "public" instead of None. The join payload drops None values, so a binding like postgres_changes("*"), or a table and filter without a schema, used to be sent without a schema, and the server rejected it. table and filter on PostgresChangesBinding now also default to None, so a binding can be built with only an event. v2: #1884.
Join reply check
subscribe() now compares the postgres_changes list in the join reply, by index, with the requested bindings (event, schema, table and filter). If the server returns fewer bindings or a different one, the channel leaves and subscribe() raises RealtimeError("mismatch between server and client bindings for postgres changes"). Before this, the channel counted as joined and no changes arrived. A reply without postgres_changes is still accepted, as in v2 and realtime-js. v2: #1929.
This check relies on the default schema: the server echoes "public", so without the default every binding without a schema would count as a mismatch.
String errors
PostgresChangesData.errors is now str | list[str] | None. The documented form is a single string and the current server sends a list. A string used to fail validation and end the messages iterator. v2: #1908.
Tests
tests/test_postgres_changes_join.py covers the default schema in the join payload, a matching reply, a missing or null filter in the reply, an empty reply without bindings, a mismatched reply (empty list, filter, table, schema and event) leaving and raising, and the three forms of errors.
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
New Features
PostgreSQL change subscriptions now use the public schema by default.
Subscription setup checks that the server’s change bindings match the requested event, schema, table, and filter. If they do not match, the channel is unsubscribed and a RealtimeError is raised.
Bug Fixes
PostgreSQL change error responses can now be handled when provided as a string, a list of strings, or null.
Postgres Changes bindings now use the public schema by default. Subscription handling validates the successful join reply and compares returned bindings with requested bindings. If the bindings do not match, the channel attempts to unsubscribe and raises RealtimeError. The PostgresChangesData.errors field now accepts a string, a list of strings, or None. Tests cover schema defaults, matching and mismatching bindings, channel cleanup, and supported error values.
Sequence Diagram(s)
sequenceDiagram
participant Client
participant RealtimeChannel
participant WebSocketTestServer
Client->>RealtimeChannel: subscribe()
RealtimeChannel->>WebSocketTestServer: phx_join
WebSocketTestServer-->>RealtimeChannel: Successful reply with bindings
RealtimeChannel->>RealtimeChannel: Compare returned and requested bindings
RealtimeChannel->>WebSocketTestServer: phx_leave on mismatch
RealtimeChannel-->>Client: Raise RealtimeError on mismatch
Loading
Change: Bug fix
Merge Risk: Minimal · up to 12928
This change sets a default schema for Postgres Changes, validates the server's join reply, and accepts a string error value. No concrete merge-blocking risk was found.
- [ ] 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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: fbf5d635-0250-479d-a036-e95a04a37e9c
Commits
Reviewing files that changed from the base of the PR and between f80e732 and 1292814.
Files selected for processing: 3
src/realtime/src/realtime/channel.py
src/realtime/src/realtime/types.py
src/realtime/tests/test_postgres_changes_join.py
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.
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.
Ports three
postgres_changesfixes from v2 to v3. Fixes SDK-2827.Default schema
PostgresChangesBinding.schemaandRealtimeChannelOptions.postgres_changes(schema=...)now default to"public"instead ofNone. The join payload dropsNonevalues, so a binding likepostgres_changes("*"), or a table and filter without a schema, used to be sent without a schema, and the server rejected it.tableandfilteronPostgresChangesBindingnow also default toNone, so a binding can be built with only an event. v2: #1884.Join reply check
subscribe()now compares thepostgres_changeslist in the join reply, by index, with the requested bindings (event, schema, table and filter). If the server returns fewer bindings or a different one, the channel leaves andsubscribe()raisesRealtimeError("mismatch between server and client bindings for postgres changes"). Before this, the channel counted as joined and no changes arrived. A reply withoutpostgres_changesis still accepted, as in v2 and realtime-js. v2: #1929.This check relies on the default schema: the server echoes
"public", so without the default every binding without a schema would count as a mismatch.String errors
PostgresChangesData.errorsis nowstr | list[str] | None. The documented form is a single string and the current server sends a list. A string used to fail validation and end themessagesiterator. v2: #1908.Tests
tests/test_postgres_changes_join.pycovers the default schema in the join payload, a matching reply, a missing or nullfilterin the reply, an empty reply without bindings, a mismatched reply (empty list, filter, table, schema and event) leaving and raising, and the three forms oferrors.