Skip to content

fix: let realtime.send() broadcast payloads that aren't JSON objects - #2390

Merged
edgurgel merged 5 commits into
supabase:mainfrom
mandar1045:fix/send-non-object-payloads
Nov 23, 2026
Merged

edgurgel merged 5 commits into
supabase:mainfrom
mandar1045:fix/send-non-object-payloads

Conversation

@mandar1045

@mandar1045 mandar1045 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2389

realtime.send() adds the message id to the payload with jsonb_set, which errors on anything that isn't an object, so arrays, strings, numbers and null were dropped with only a WARNING.

This only adds the id when the payload is an object without one, and passes any other JSON value through as-is, like send() did before #1602. Object payloads behave the same as now.

Broadcast replay loaded realtime.messages.payload as :map, so once a non-object payload was stored, every replay join on that topic failed with cannot load [1, 2, 3] as type :map. That already happens on main if a row like that is inserted directly. Realtime.Api.Message now uses a small Ecto type that loads any JSON value.

  • New migration redefining realtime.send() with that change only
  • Regenerated tenant_schema and the pg15/pg17 dumps
  • Realtime.Api.JsonPayload type for Message.payload
  • Integration tests send arrays, strings, numbers, booleans and null with realtime.send() and check they arrive live and on replay
  • e2e replay case in broadcast-replay.ts

@mandar1045
mandar1045 force-pushed the fix/send-non-object-payloads branch from ae78851 to 51d12ce Compare October 20, 2026 13:21
@edgurgel

Copy link
Copy Markdown
Member

@mandar1045 could we also check how messages replay would work with this? I'm not sure the Ecto type here would handle non-JSON objects.

Also improving the e2e integration test would be great as well

@mandar1045

Copy link
Copy Markdown
Contributor Author

@mandar1045 could we also check how messages replay would work with this? I'm not sure the Ecto type here would handle non-JSON objects.

Also improving the e2e integration test would be great as well

Sure

@mandar1045
mandar1045 force-pushed the fix/send-non-object-payloads branch from 603ed48 to 4ad6381 Compare October 22, 2026 06:31
@mandar1045

Copy link
Copy Markdown
Contributor Author

replay was failing on non-object payloads (cannot load [1, 2, 3] as type :map, kills the whole join, happens on main too with a direct insert). Switched Message.payload to a type that loads any JSON value, added live + replay tests for all non-object types and an e2e replay case

@mandar1045

Copy link
Copy Markdown
Contributor Author

@edgurgel I looked into the replay question. Replay was actually breaking on these payloads too, so I fixed that as well. Arrays, strings, numbers, booleans and null now work both live and on replay, and there are tests for each. Let me know if anything else needs changing. Thanks.

realtime.send() adds the message id to the payload with jsonb_set, which
errors on anything that isn't an object, so arrays, strings, numbers and
null were dropped with only a WARNING.

Only add the id when the payload is an object without one, and pass any
other JSON value through as-is.

Broadcast replay loaded the payload as a map, so a stored non-object
payload broke every replay join on that topic. Load any JSON value
instead.

Fixes supabase#2389
@mandar1045
mandar1045 force-pushed the fix/send-non-object-payloads branch from 0967528 to 983675c Compare November 3, 2026 15:17
# Conflicts:
#	lib/realtime/tenants/migrations.ex
#	priv/repo/tenant_db_dump_15.sql
#	priv/repo/tenant_db_dump_17.sql
@edgurgel

edgurgel commented Nov 9, 2026

Copy link
Copy Markdown
Member

@edgurgel I looked into the replay question. Replay was actually breaking on these payloads too, so I fixed that as well. Arrays, strings, numbers, booleans and null now work both live and on replay, and there are tests for each. Let me know if anything else needs changing. Thanks.

Thanks! Will take a look later this week!

@edgurgel
edgurgel merged commit ea911bf into supabase:main Nov 23, 2026
55 checks passed
@mandar1045
mandar1045 deleted the fix/send-non-object-payloads branch November 23, 2026 01:08
@realtime-release-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.174.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

realtime.send() silently drops payloads that aren't JSON objects

2 participants