Keep a split part's own state when the split is edited #5933
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #5933"
general
weight: 0.35
jaysbeekay
Closes #5545
Fork pre-flight: jaysbeekay/sure#1004, same branch (
up/split-edit-keeps-parts), same commit (8751a165f). Three commits onmaine0d9c9c16, then merges ofmain12cd4e1a5and19cdb5a75, both clean.This covers the bug in #5545. The issue's second question, whether a split part can be a transfer leg, is left to #5809, which answers it.
Problem
Saving the split editor destroyed every part and built new ones from the form. A part lost its activity label, notes, attachments, attribute locks and exclusion, even when the edit didn't touch it.
What changed
A part that is still in the split is now updated in place and keeps everything the form doesn't set.
app/views/splits/edit.html.erb,_row.html.erb: each existing row posts its part's entry id in a hidden field. A row added in the dialog posts none, and neither does the create dialog.SplitsController: permitsidand passes it throughbuild_splits.Entry#resplit!: when any split hash carries an id,update_split_parts!runs under the existing split lock:- ids are looked up through
child_entriesonly. An id that isn't one of this split's parts, or that appears twice, raisesRecordInvalidand nothing changes.- The amounts must still sum to the parent.
-
refuse_while_split_part_transferred!runs first, asunsplit!does, so a part that is a confirmed transfer leg still blocks the edit (#4966).- Parts left out are destroyed. Kept parts get name, amount, category, merchant and tags. Rows without an id become new parts, built the same way
split!builds them.- With no ids at all (API, rules), it still replaces every part.
- A kept part whose tag ids change gets its entry touched. Tags are saved as taggings alone, so without the touch a tag-only change saved neither the transaction nor the entry,
Family#entries_cache_versionstayed put, and a tag-filtered search's cached totals were served stale. The old destroy-and-recreate always moved the version, and so does the transaction form.Api::V1::SplitsController#update: comment only. It no longer says parts are replaced "exactly as the web UI does it". The API still replaces.Entry#split!: no behaviour change. Its total check and part builder moved intoensure_split_total!andcreate_split_part!so the in-place path reuses them.Exclusion. The edit form has no exclusion field, so
excludedarrives unset. Writing it would clear an exclusion set from the transaction drawer, the same loss this fixes. A kept part's exclusion changes only when the hash setsexcluded.Locks. A kept part keeps its
locked_attributeson the entry and the transaction. A changed category or merchant on a kept part gets no new lock, the same as a new part from the web form today (split!locks only withlock_attributes: true, whichresplit!doesn't pass). If #5492 lands, its rule should apply to both paths.Tests
| Test | Before the fix |
|---|---|
|
EntrySplitTest"resplit! keeps a kept part's label, notes and attachment by id": remove part 1, keep part 2 by id with a new name and amount |RecordNotFound: part 2 was a new record || "resplit! leaves a kept part's locks alone" (entry and transaction locks) |
RecordNotFound|| "resplit! by id refuses while a kept part is a confirmed transfer leg" | passes both ways (the old path refused through
unsplit!); guards the new path || "resplit! by id keeps a pending match, which then can't be confirmed with unequal amounts" |
RecordNotFound|| "resplit! refuses a part id from another split and changes nothing" | nothing raised |
| "resplit! refuses the same part id on two rows" | nothing raised |
| "resplit! by id still requires the parts to sum to the parent" | passes both ways; guards the new path |
| "resplit! by id creates a row with a blank id as a new part like split! does" | fails: part 1 is replaced too |
| "resplit! by id keeps a kept part's exclusion when the row doesn't set it" |
RecordNotFound|| "resplit! by id updates a kept part's category, merchant and tags" |
RecordNotFound|| "resplit! by id refuses to remove a confirmed transfer leg" | passes; guards where the refusal sits (see Mutations) |
| "resplit! by id changes nothing when a kept row fails validation after a removal" | passes; guards the rollback of the removal |
| "resplit! by id moves the family's entries cache version on a tag-only change" | version unchanged |
| "resplit! by id moves a tag-filtered search's totals cache key on a tag-only change" |
cache_key_baseunchanged ||
SplitsControllerTest"edit posts each existing part's id and none for a new row" | no id fields || "update keeps a part's activity label" (through the form) |
RecordNotFound|| "update refuses a part id from another split" | no alert |
The existing "resplit! replaces the children of a split" (no ids) still passes unchanged.
Mutations, one at a time:
| Mutation | Caught by |
|---|---|
| Always replace all parts | 10 tests |
| Match rows to parts by position, not id | label/notes/attachment test, both foreign-id tests |
| Drop the id check | foreign-id (model, controller) and duplicate-id tests |
| Drop the transfer-leg refusal on the in-place path | confirmed-leg test |
| Always overwrite
excluded| exclusion test || Drop the sum check on the in-place path | sum test |
| Form omits the hidden id | edit-form id test |
| Controller drops
id| both controller update tests || Kept part's category/merchant/tags not updated | field-update test |
| Kept part's amount not updated | 3 tests |
| Transfer-leg refusal moved below the destroy loop | remove-a-leg test only: destroying the part cascades its transfer |
|
with_split_lockwithout its transaction | rollback test only || Tag-change touch dropped | both cache tests |
Validation
8751a165f: 19,555 runs, 0 failures, 9 skips; the 8 errors areReleaseNotesWorkflowTest, which needsnode, missing in the test image.test/system/splits_test.rb,transfers_test.rb: 5 runs, 0 failures on the pre-merge head. "edit dialog saves the merchant and tags picked with the DS pickers" now goes through the in-place path.Screenshots
None. The only markup change is a hidden input, so nothing visible changes.
Blast radius
resplit!callers:SplitsController#update(now sends ids) andApi::V1::SplitsController#update(permits noid, so it keeps replace-all).split!callers, behaviour unchanged:split_once!(web create, API create,Rule::ActionExecutor::SplitTransaction),Family::DataImporter#import_split_lines!,QifImport. The create form posts no ids, andcreate_split_part!ignores:id._row.html.erbis shared withnew.html.erb.iddefaults tonil, so the create dialog renders no hidden field.lock_attributes:toresplit!), #5507 (parent's label on new parts, insplit!), #5736 (moving a split's date inbulk_update!), #5809 (transfer legs), #5833 and #5734 (other markup in the split dialog). None changesresplit!'s replace logic. Whichever lands first, this rebases onto.Migration notes
No migration.
<!-- This is an auto-generated description by cubic. -->
---
Summary by cubic
Fixes #5545. Saving the split editor rebuilt every part from the form, so a part lost its activity label, notes, attachments, locks and exclusion even when the edit didn't touch it.
The edit form now posts each existing part's id, and
Entry#resplit!updates matched rows in place. A row without an id becomes a new part, and rows missing from the edit are removed. A call with no ids at all (the API, rules) still replaces every part.excludedunless the row sets it, and keep their locks.Transfer#confirm!re-reads both legs under the lock, so a resplit that changed a kept part's amount can't be confirmed with legs that no longer offset.<sup>Written for commit 5877fb40198ec1378c8222645d6bfb97067b3807. Summary will update on new commits.</sup>
<a href="https://cubic.dev/pr/we-promise/sure/pull/5933?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Editing a split now updates existing parts in place, preserving their labels, notes, attachments, locks, and exclusions when applicable. You can also add new parts or remove omitted ones.
Bug Fixes
Split edits with invalid part IDs, invalid totals, or confirmed transfer parts are rejected without changing existing parts. If a split changed elsewhere, you’re prompted to reopen it before retrying.
Transfer confirmation checks the latest transaction amounts, and invalid confirmations display an alert without confirming the transfer.
Documentation
* API guidance clarifies that replacing split parts removes and recreates them, so callers should submit the full desired set.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->