fix(featureflag): make create idempotent to stop duplicate-key crash - #354
Merged
Merged
Conversation
Fixes duplicate key constraint violation when creating a feature flag that already exists for a user (e.g. theme-switcher). Adds openspec change proposal/specs/design/tasks deciding on idempotent create (update-on-duplicate, 201 for new / 200 for existing) and TDD-red tests exercising the new contract ahead of implementation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
FeatureFlagService.create() now checks for an existing (user_id, feature) flag via the repository's findByUserAndFeature() and updates it in place instead of blindly persisting, which previously threw a duplicate key constraint violation on ix_user_feature_flag_user_id_name when recreating an existing flag (e.g. toggling theme-switcher twice). Dropped the originally planned 201/200 status-code split: the generated UserFeatureFlagsApi interface returns a plain FeatureFlagDto because returnResponse=false in build.gradle.kts, and enabling a dynamic status would require flipping that project-wide, touching every resource interface. Tracked separately as #353. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Moves the completed change to archive/2026-09-18-fix-duplicate-feature-flag-create and syncs its delta spec into a new main spec at openspec/specs/user-feature-flags/spec.md, documenting the idempotent create requirement and the existing update-by-ID requirement. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
FeatureFlagService.create()now checks for an existing(user_id, feature)flag viaUserFeatureFlagRepository.findByUserAndFeature()and updates it in place instead of blindly persisting, which previously threw a duplicate key constraint violation onix_user_feature_flag_user_id_namewhen the flag already existed (e.g. togglingtheme-switchertwice).openapi.yamlcontract exactly — no codegen or contract changes needed.UserFeatureFlagsApiinterface returns a plainFeatureFlagDtobecausebuild.gradle.ktssets thejaxrs-specgenerator'sreturnResponseoption tofalseproject-wide. Enabling a dynamic per-call status code would require flipping that globally, changing every generated resource interface's method signature across the app. Tracked separately as #353.fix-duplicate-feature-flag-create(proposal/specs/design/tasks), now archived, and synced a newuser-feature-flagsmain spec documenting the idempotent-create and update-by-ID requirements.Test plan
FeatureFlagServiceTest: new-pair create persists a new flag; existing-pair create updates in place instead of persisting.FeatureFlagResourceTest(real@QuarkusTest+ Postgres): create-new, create-existing (200 + same ID), repeated identical POSTs, and a dedicatedtheme-switcherregression test recreating the exact flag from the original bug report../gradlew test— full suite green, no regressions.openspec validate --specs— 7/7 pass.🤖 Generated with Claude Code