supabase / realtime

Broadcast, Presence, and Postgres Changes via WebSockets
https://supabase.com/realtime
Apache License 2.0
6.7k stars 299 forks source link

Realtime RLS Problems - Cannot INSERT or UPDATE, only DELETE #1114

Open rexhibition opened 1 month ago

rexhibition commented 1 month ago

Bug report

Describe the bug

My Supabase table when I set the primary key column to be NanoID caused a problem with Realtime detecting changes.

vivaldi_B6QNT33q6V

Basically, it only registers DELETE. When I INSERT or UPDATE anything in the table, Realtime doesn't detect it. When I set the primary key back to UUID by default, it's working fine.

However, when I disable RLS completely from that table. The Realtime works normally with NanoID. So I think there might be some problem with the RLS or authentication.

Screenshots

My VueJS code for subscribing & submiting data. Code_1ZyJE0cfOh Code_2eC6h1aRHl

I even tried to create a public RLS but still not working. vivaldi_XAQuOd0Ew3

System information

barrownicholas commented 1 month ago

I am experiencing this also, I was just coming to report this behavior... here's a video (below). I can also confirm that I am seeing 100% of what @rexhibition is reporting.

As seen in the video below:

https://github.com/user-attachments/assets/f272ffa9-1cdb-41e0-b042-34733c007efe


        SERVICE IMAGE      │      LOCAL       │ LINKED
  ─────────────────────────┼──────────────────┼─────────
    supabase/postgres      │ 15.1.1.78        │ -
    supabase/gotrue        │ v2.151.0         │ -
    postgrest/postgrest    │ v12.2.0          │ -
    supabase/realtime      │ v2.29.15         │ -
    supabase/storage-api   │ v1.0.6           │ -
    supabase/edge-runtime  │ v1.55.0          │ -
    supabase/studio        │ 20240729-ce42139 │ -
    supabase/postgres-meta │ v0.83.2          │ -
    supabase/logflare      │ 1.4.0            │ -
    supabase/supavisor     │ 1.1.56           │ -
barrownicholas commented 1 month ago

@filipecabaco just wanted to flag this on your end. Another weird thing about this bug... I am only experiencing this on the newest CLI version, with tables created after updating to v 1.187.10. All of my old tables, created prior to updating, have no issues whatsoever.

barrownicholas commented 1 month ago

@filipecabaco major update to help debug this:

I am experiencing this issue as early as supabase cli 1.187.10 (which, in turn, uses realtime 2.29.15 (via https://github.com/supabase/cli/releases/tag/v1.181.2)

I am not experiencing this issue on supabase cli 1.178.6 (which, in turn, uses realtime 2.29.13 (via https://github.com/supabase/cli/releases/tag/v1.178.6)

My best guess is that 2.29.15 broke how Realtime interprets RLS policies (since 1.178.6 used 2.29.13 and 1.187.10 used 2.29.15). This actually makes sense, because 2.29.15 does in fact change how RLS is interpreted by realtime: https://github.com/supabase/realtime/pull/1085 (I think #1085 might have broken something with how postgres_changes are interpreted against RLS).

As a temporary work-around @rexhibition , you can use npx -y supabase@1.178.6 ... (such as npx -y supabase@1.178.6 start) to revert back to a working RLS version while this gets straightened out.

rexhibition commented 1 month ago

@filipecabaco major update to help debug this:

I am experiencing this issue as early as supabase cli 1.187.10 (which, in turn, uses realtime 2.29.15 (via https://github.com/supabase/cli/releases/tag/v1.181.2)

I am not experiencing this issue on supabase cli 1.178.6 (which, in turn, uses realtime 2.29.13 (via https://github.com/supabase/cli/releases/tag/v1.178.6)

My best guess is that 2.29.15 broke how Realtime interprets RLS policies (since 1.178.6 used 2.29.13 and 1.187.10 used 2.29.15). This actually makes sense, because 2.29.15 does in fact change how RLS is interpreted by realtime: #1085 (I think #1085 might have broken something with how postgres_changes are interpreted against RLS).

As a temporary work-around @rexhibition , you can use npx -y supabase@1.178.6 ... (such as npx -y supabase@1.178.6 start) to revert back to a working RLS version while this gets straightened out.

Thank you for your thorough report and suggested workaround. I hope this issue is resolved soon! 😊 I was a bit worried since hardly anyone had reported this before.

filipecabaco commented 1 month ago

thank you so much @barrownicholas 🙏

@rexhibition was the bug happening in an existing project, if so indeed one of the migrations could have broken something.

Plus the subcriber_pool_size is indeed wrong, not even sure how it changed 🤦

rexhibition commented 3 weeks ago

@barrownicholas Hi, do you have a problem with nanoid when you insert a new item? When I console log the payload.new, I saw that my shortid column, which is the nanoid column returns with only a letter. But I checked my Supabase server and saw the full nanoid is still showing properly.

image