Failing to update data because of row level security returns [] as response body #1844
-
EnvironmentUsing Supabase. Description of issueResponse body of update is just an empty array when failed to perform the update due to row level security. To ReproduceCreate a sample table: create table public.sample (
id uuid not null primary key DEFAULT uuid_generate_v4 (),
name text not null
);
alter table public.sample enable row level security; Perform an update const {data, error} = await postgrestClient.from('sample').update({id: ''}) And the error value is Expected behaviorGet an error response message saying something like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
This is just how RLS works. There is no error and it makes sense. RLS limits the number of rows a user can "see" on the table. In your example, you are not seeing any rows - so no rows are updated, there is no error and the result is empty. All correct. There can be a difference between the rows you are seeing and the rows you are allowed to update. This is the difference between On a side note: If you want to do an update where you expect to change exactly one row, not more and not less, you can request a single row via |
Beta Was this translation helpful? Give feedback.
-
Would the update throw an error for a policy violation if the policy has a USING and a WITH CHECK? Does the addition of a WITH CHECK produce the error on Update? |
Beta Was this translation helpful? Give feedback.
This is just how RLS works. There is no error and it makes sense. RLS limits the number of rows a user can "see" on the table. In your example, you are not seeing any rows - so no rows are updated, there is no error and the result is empty. All correct.
There can be a difference between the rows you are seeing and the rows you are allowed to update. This is the difference between
USING
andWITH CHECK
. Have a look here at Table 272.On a side note: If you want to do an update where you expect to change exactly one row, not more and not less, you can request a single row via
Accept
header - see the docs. This would fail in your example, because 0 rows is not "exactly 1 row". Not sure how t…