Skip to content

fix(realtime): port the v2 postgres_changes fixes - #2052

Merged
spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2827-realtime-port-the-v2-postgres_changes
Nov 13, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2827-realtime-port-the-v2-postgres_changes

Conversation

@spydon

@spydon spydon commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

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.

@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

  • 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.

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: 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.

@spydon
spydon merged commit b672e62 into main Nov 13, 2026
26 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2827-realtime-port-the-v2-postgres_changes branch November 13, 2026 16:28
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