fix(custom-fields): guard option removals in use and revalidate default on update#41
Merged
Merged
Conversation
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
Two silent failure modes on
PUT /custom-fields/{id}get explicit errors so admins can act on them instead of corrupting downstream data.Removing an option that is still in use leaves orphans. If a
single_selectfield hasvalue="p2"on existing bugs and the admin dropsp2from the option set, the bug rows keepp2as a ghost — the form can't re-select it and any later PUT that omitscustom_fieldsstrips the value entirely. New helper_option_values_in_usescans the entity table (bugs/test_cases/test_executions) for stored values referencing the field key (both string and list-of-string shapes), and_guard_options_changerefuses the request with409naming the offending values. Admins are told to migrate the values or archive the field instead.Replacing the option set without revisiting the default crashes future creates. A field with
required=true+default_value="p0"becomes a landmine the momentp0leaves the options list:_apply_default_or_requirestampsp0on every new row, thenvalidate_payloadrejects it with a confusing422aimed at the wrong user. The same guard now revalidatesdefault_valueagainst the new options set on the same request, returning422with the offending values (single string forsingle_select, list of items formulti_select). Admins can either update the default in the same payload (accepted) or set it toNone.Notes:
optionsis part of the update payload and the field type issingle_select/multi_select. Pure metadata edits (label, required, archived) are untouched.default_value=Noneto confirm clearing still works.