Repository navigation
Conversation
…er delete A hard delete that a foreign key, restrict rule or trigger refuses now returns 409 with the code user_delete_blocked and the Postgres message in the 2024-01-01 error format, instead of 500 unexpected_failure. The initial format is unchanged. Fixes supabase#2972 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2972.
What changed
DELETE /admin/users/{id}(hard delete) now maps a Postgres error thatutilities.NewPostgresErroralready treats as public, such as a foreign key withouton delete cascade(23503) or a trigger that raises (P0001), to a 409 with a new error code:{ "code": "user_delete_blocked", "message": "Database error deleting user: update or delete on table \"users\" violates foreign key constraint ..." }Before, the
2024-01-01error format (which auth-js sends on every request) answered 500unexpected_failure, so a service-role caller couldn't tell a blocked delete from a server failure. Any other database error still returns 500unexpected_failure.Requests without
X-Supabase-Api-Versionare unchanged:handleResponseErrorHTTPstill finds the Postgres error throughInternalErrorand returns it as before, with the same status.Tests
TestAdminUserDeleteBlockedByDatabasecreates a table inauthwith a foreign key toauth.users, deletes the user with and without the2024-01-01header, and checks the code, status, message and that the user still exists. It fails without the change inadmin.go.go test ./internal/... -p 1passes against a local Postgres 17 migrated withhack/migrate.sh.Follow-up outside this repo
auth-js would need
user_delete_blockedin itsErrorCodeunion; I can open that once the code name is settled.🤖 Generated with Claude Code