Skip to content

fix: preserve special string values in in filters - #2519

Open
valkiara wants to merge 1 commit into
supabase:mainfrom
valkiara:fix/realtime-in-filter-values
Open

valkiara wants to merge 1 commit into
supabase:mainfrom
valkiara:fix/realtime-in-filter-values

Conversation

@valkiara

@valkiara valkiara commented Nov 6, 2026

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix. Moves the filter-value correction to the server, as requested by @leandrocp in supabase/supabase-js#2738 (comment).

What is the current behavior?

The subscription parser replaces the outer parentheses of an in list with braces and passes its contents directly to PostgreSQL. PostgreSQL then interprets unquoted NULL as a null element, rejects empty elements, and treats braces as array syntax. For example, details=in.(NULL,{tag},a{b},) cannot preserve those four strings.

What is the new behavior?

Quote empty elements, case-insensitive NULL text, and braces when constructing the PostgreSQL array literal. Apply the same conversion to not.in. Keep ordinary values and already quoted elements unchanged, including escaped quotes, backslashes, commas, and parentheses.

The list scanner recognizes quoted values after every comma, including optional leading whitespace. Top-level filter splitting and scalar operators retain their existing behavior. No migration or client dependency change is needed.

in.() still represents an empty list. A single empty string must be written as in.(""): the wire format cannot distinguish an empty list from a client's one-element list serialized without quotes. This preserves the server's existing empty-list behavior.

Additional context

Tests cover parsing for both operators, stored PostgreSQL array values, and actual row delivery through realtime.list_changes for matching and nonmatching subscriptions.

Validated locally with the repository-pinned Elixir 1.19.5 / OTP 28.5.0.4 and supabase/postgres:17.11.0.014, using the external tenant DB backend:

  • The final parser regression set has 12 failures on unchanged upstream and passes all 22 cases after the fix. The new database/row-delivery regression also fails on unchanged upstream with a malformed array literal.
  • mix test test/extensions/postgres_cdc_rls/ test/integration/rt_channel/postgres_changes_test.exs test/integration/rt_channel/postgres_changes_filters_test.exs --max-failures 5: 12 doctests, 318 tests, zero failures (6 backend-specific exclusions).
  • mix compile --force --warnings-as-errors, mix format --check-formatted, mix credo, and git diff --check pass.

The full-suite attempt is not green: mix test --max-failures 5 stopped after 22 doctests and 1,744 tests with five failures outside the changed parser: a catalog fixture's function-source mismatch, a missing pgdelta executable, a 500 ms column-selection WebSocket timeout, IPv6 DNS resolution, and a WAL-slot lag assertion. After installing the pinned pgdelta, a targeted rerun with the unchanged upstream parser still failed on DNS (ipv6.google.com returned nxdomain) and the slot-lag assertion (slot_inactive rather than lag_too_high); the other selected checks passed. The six-version PostgreSQL CI matrix has not been run locally.

This branch has not been deployed

No deployments
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