Repository navigation
fix: let realtime.send() broadcast payloads that aren't JSON objects - #2390
Conversation
ae78851 to
51d12ce
Compare
|
@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 |
603ed48 to
4ad6381
Compare
|
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 |
4ad6381 to
4e98c17
Compare
|
@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
0967528 to
983675c
Compare
# Conflicts: # lib/realtime/tenants/migrations.ex # priv/repo/tenant_db_dump_15.sql # priv/repo/tenant_db_dump_17.sql
Thanks! Will take a look later this week! |
|
🎉 This PR is included in version 2.174.4 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Fixes #2389
realtime.send()adds the messageidto the payload withjsonb_set, which errors on anything that isn't an object, so arrays, strings, numbers andnullwere dropped with only aWARNING.This only adds the
idwhen the payload is an object without one, and passes any other JSON value through as-is, likesend()did before #1602. Object payloads behave the same as now.Broadcast replay loaded
realtime.messages.payloadas:map, so once a non-object payload was stored, every replay join on that topic failed withcannot load [1, 2, 3] as type :map. That already happens on main if a row like that is inserted directly.Realtime.Api.Messagenow uses a small Ecto type that loads any JSON value.realtime.send()with that change onlytenant_schemaand the pg15/pg17 dumpsRealtime.Api.JsonPayloadtype forMessage.payloadnullwithrealtime.send()and check they arrive live and on replaybroadcast-replay.ts