fix: keep a persisted field's code stable when its name is renamed [3.x] - #201
Merged
Conversation
The name input derived `code` from `name` whenever the current code still matched the slug of the previous name. That heuristic is right while a field is being created, but on a persisted field the code is an identity rather than a label: stored values, report columns and visibility conditions all key on it, and a field cloned onto a new form version shares its code with the original. Renaming such a field therefore rewrote the code and silently severed it from its own data — the values kept the old code, and reporting saw two unrelated columns where the user expected one renamed column. Only derive the code while the field is being created. Both create actions bind no record so they are unaffected; both edit actions bind one, which is what now suppresses the rewrite. The duplicate action does not use this form and already generates its own unique code.
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.
Problem
The
nameinput onFieldFormderivescodefromnamewhenever the current code still matches the slug of the previous name:That heuristic is correct while a field is being created — it stops overwriting a code the user typed by hand. On a persisted field it is wrong: the code is an identity, not a label. Stored values, report columns and visibility conditions all key on it, and a field cloned onto a new form version deliberately shares its code with the original.
So renaming a field silently rewrote its code and severed it from its own data: the existing values kept the old code, and reporting then offered two unrelated columns where the user expected one renamed column.
Fix
Only derive the code while the field is being created, detected by the absence of a bound record.
This is correctly scoped across all four
FieldForm::schema()consumers:ManageCustomFieldSection::createFieldManageFieldsTablecreate actionManageCustomField::editActionManageFieldsTable::editFieldduplicateActiondoes not use this form — it is confirmation-only and already generates its own unique code viagenerateUniqueCode(), so it is unaffected.Verification
New regression test in
CustomFieldsFieldManagementTest, verified red against the previous implementation (it failed on thecodeassertion) and green with the fix.Downstream
This is the blocker for Padmission/journey#3427, where renaming a field on a new Flex Fund form version broke code continuity with v1 and hid the field from Custom Reports. Journey will need a version bump once this is released.