fix(features): return 400 instead of 500 on feature name race condition#7838
Open
narendraio wants to merge 1 commit into
Open
fix(features): return 400 instead of 500 on feature name race condition#7838narendraio wants to merge 1 commit into
narendraio wants to merge 1 commit into
Conversation
When two requests create a feature with the same name concurrently, both can pass `validate_name` before either is persisted. The second insert then trips the case-insensitive `lowercase_feature_name` unique constraint, raising an unhandled `IntegrityError` that surfaces as an HTTP 500. Catch the `IntegrityError` during creation and re-raise it as a validation error so the client receives a clear 400 response, consistent with the existing duplicate-name validation. Closes Flagsmith#6617
|
@narendraio is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
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.
Description (replace the blank template with this):
docs/if required so people know about the feature.Changes
Closes #6617
When two requests create a feature with the same name concurrently, both can
pass
validate_namebefore either is persisted. The second insert then tripsthe case-insensitive
lowercase_feature_nameunique constraint, raising anunhandled
IntegrityErrorthat surfaces to the client as an HTTP 500.This catches the
IntegrityErrorduring creation and re-raises it as avalidation error, so the client receives a clear 400 response consistent with
the existing duplicate-name validation. The duplicate-name message is extracted
into a shared constant so both code paths stay in sync.
How did you test this code?
Added a unit test (
test_create_feature__name_race_condition__returns_400) thatsimulates the race by letting
validate_namepass while the database stillrejects the duplicate name, and asserts the endpoint responds with a 400 and the
expected error message. Verified locally against Postgres: