Skip to content

Fix ingredient editor nested attributes index collision#3798

Merged
tvdeyen merged 1 commit intomainfrom
fix-ingredient-nested_attributes
Mar 27, 2026
Merged

Fix ingredient editor nested attributes index collision#3798
tvdeyen merged 1 commit intomainfrom
fix-ingredient-nested_attributes

Conversation

@tvdeyen
Copy link
Copy Markdown
Member

@tvdeyen tvdeyen commented Mar 27, 2026

What is this pull request for?

The form_field_counter method used the ingredient's position in the YAML element definition to generate the nested attributes index. This caused collisions where two ingredients could end up with the same index, corrupting form data on save.

Use the ingredient's database ID as the nested attributes key instead. Rails accepts_nested_attributes_for does not require sequential indices, it only needs unique keys to group fields for each record. Since each ingredient has a unique ID, this eliminates any possibility of collision.

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

@tvdeyen tvdeyen requested a review from a team as a code owner March 27, 2026 15:59
@tvdeyen tvdeyen added bug backport-to-8.1-stable Needs to be backported to 8.1-stable labels Mar 27, 2026
@tvdeyen tvdeyen force-pushed the fix-ingredient-nested_attributes branch from cc21d4e to 97b06d1 Compare March 27, 2026 16:00
The form_field_counter method used the ingredient's position in the YAML
element definition to generate the nested attributes index. This caused
collisions where two ingredients could end up with the same index,
corrupting form data on save.

Use the ingredient's database ID as the nested attributes key instead.
Rails accepts_nested_attributes_for does not require sequential indices,
it only needs unique keys to group fields for each record. Since each
ingredient has a unique ID, this eliminates any possibility of collision.

Signed-off-by: Thomas von Deyen <vondeyen@blish.cloud>
@tvdeyen tvdeyen force-pushed the fix-ingredient-nested_attributes branch from 97b06d1 to 31fabf1 Compare March 27, 2026 16:20
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.48%. Comparing base (a7b98f4) to head (31fabf1).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3798   +/-   ##
=======================================
  Coverage   97.48%   97.48%           
=======================================
  Files         320      320           
  Lines        8497     8497           
=======================================
  Hits         8283     8283           
  Misses        214      214           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tvdeyen tvdeyen merged commit c371500 into main Mar 27, 2026
28 checks passed
@tvdeyen tvdeyen deleted the fix-ingredient-nested_attributes branch March 27, 2026 16:37
@alchemycms-bot
Copy link
Copy Markdown

💚 All backports created successfully

Status Branch Result
8.1-stable

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-8.1-stable Needs to be backported to 8.1-stable bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant