You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Delete returns a success status code even if it actually failed due to RLS policies #334
When I tried to delete a row from a table where I forgot to set up a permissive DELETE policy, the client kept returning a successful response code, even though the row wasn't deleted.
To Reproduce
Set up a Supabase table with RLS enabled but without any DELETE policies
In the provided application code, an exception is logged and re-thrown
In the client's MakeRequest method in Helper.cs, response.IsSuccessStatusCode is false in the following code block, and the method proceeds to create and throw a PostgrestException
I am able to reduplicate it myself, but I'm not sure what approach to take to rectify it. Would love some input.
The hosted supabase instance will return the rows it has deleted as its content when processing a DELETE request. When a DELETE request fails because of RLS or because there are no rows affected, it will return an empty array: [ ]. Because of this, the actual HTTP Status code is a success. Alternatively, it will return an array of model content when it succeeds.
I don't believe the solution is to mark any empty return from a DELETE request to be an exception (as a filter with no matching content isn't an exception imo).
So, one solution would be to change the void return type on Table.cs to ModeledResponse and the developer could verify the rows have been deleted in the response. This seems less than ideal to me though.
Another would be to change the void return type on Table.cs to bool and execute a COUNT using the provided filter first, then do the DELETE, then verify the count matches the returned DELETE rows.
The problem is the SDK cannot determine on its own if the deletion failed. PostgREST returns a 200 + empty body for the following scenarios:
RLS blocked the delete (error)
Filter matched no rows at all, equivalent of an idempotent delete of a non-existing row (success)
This decision (success vs. failure) is out-of-scope for the SDK, and it's up to the caller to evaluate the outcome of Delete. Nonetheless, it means we must provide such information, which leads to a breaking change in the Delete signature: returning a Task<BaseResponse> instead of a Task.
The latest solution provided in the previous post could be a good workaround, but it has flaws. It transforms the operation from a "Delete" to a "Verify, then Delete, and Verify again". Returning a bool works only when you expect to delete a single element (binary, either it succeeded or failed); if you aim to delete multiple rows, you cannot represent a partial deletion with a binary result (ex: I wanted to delete 3 entities, and only 2 actually got deleted).
This fix will therefore get included in the next major version. I hope it will land in coming months. I assume it's not a real problem, as this issue was filled more than 2 years ago.
Activity
acupofjose commentedon Apr 16, 2024
Hey @oli-g-sk - thanks for the issue!
I am able to reduplicate it myself, but I'm not sure what approach to take to rectify it. Would love some input.
The hosted supabase instance will return the rows it has deleted as its content when processing a DELETE request. When a DELETE request fails because of RLS or because there are no rows affected, it will return an empty array:
[ ]. Because of this, the actual HTTP Status code is a success. Alternatively, it will return an array of model content when it succeeds.I don't believe the solution is to mark any empty return from a DELETE request to be an exception (as a filter with no matching content isn't an exception imo).
So, one solution would be to change the
voidreturn type onTable.cstoModeledResponseand the developer could verify the rows have been deleted in the response. This seems less than ideal to me though.Another would be to change the
voidreturn type onTable.cstobooland execute aCOUNTusing the provided filter first, then do the DELETE, then verify the count matches the returned DELETE rows.Thoughts?
Tr00d commentedon Jul 10, 2026
The problem is the SDK cannot determine on its own if the deletion failed. PostgREST returns a 200 + empty body for the following scenarios:
This decision (success vs. failure) is out-of-scope for the SDK, and it's up to the caller to evaluate the outcome of
Delete. Nonetheless, it means we must provide such information, which leads to a breaking change in theDeletesignature: returning aTask<BaseResponse>instead of aTask.The latest solution provided in the previous post could be a good workaround, but it has flaws. It transforms the operation from a "Delete" to a "Verify, then Delete, and Verify again". Returning a
boolworks only when you expect to delete a single element (binary, either it succeeded or failed); if you aim to delete multiple rows, you cannot represent a partial deletion with a binary result (ex: I wanted to delete 3 entities, and only 2 actually got deleted).This fix will therefore get included in the next major version. I hope it will land in coming months. I assume it's not a real problem, as this issue was filled more than 2 years ago.
fix(postgrest)!: return deleted rows from parameterless Delete (supab…