Repository navigation
A failed expense edit restores an old copy and erases a newer receipt or description - #107149
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d9cc636a5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, | ||
| value: { | ||
| ...transaction, | ||
| ...getTransactionRevertValues(transaction, optimisticTransaction), |
There was a problem hiding this comment.
Include merge-specific writes in the transaction rollback
When an unreported expense merge selects the other expense's receipt, getOnyxTargetTransactionData() appends that receipt write after this builder returns (MergeTransaction.ts:404-410). The optimisticTransaction passed here still contains the original receipt, so the failure patch omits the receipt replacement. After MERGE_TRANSACTION fails, the target therefore keeps the source receipt instead of recovering its original one. The previous full-transaction rollback restored it. Add scoped failure updates for the appended merge writes, including the distance metadata at MergeTransaction.ts:415-432, or derive the rollback from the combined optimistic writes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
added the refactor. The receipt and distance writes that getOnyxTargetTransactionData adds after the builder now get their own failure entries built with the same helper, so a failed merge restores the target's own receipt and distance data
|
@rinej Please have a look at the following issue. I am curious if we should leave
Actual: The merchant is back to its original value and the error is shown. The new image is still there, and it shows Verified from the receipt you replaced. Expected: The merchant reverts and the error is shown. The new image stays, and it does not show Verified. 107091-issue-002.mp4 |
getOnyxTargetTransactionData adds receipt and distance writes to the target expense after the edit builder returns, and the builder's failure data only reverts what the builder wrote. A failed merge left the target with the other expense's receipt. Those writes now get their own scoped failure entries. Also add the file header and comments requested in review for getTransactionRevertValues. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
thanks @rojiphil for the review! Got some issues with reproducing it, but Im working on it, will share the updates soon |
|
@rojiphil I used the following receipt for it:
|
|
also addressed and pushed other review comments |
…-back-to-an-old-copy
JmillsExpensify
left a comment
There was a problem hiding this comment.
No product review required.
@rinej Yeah, this works great now. Thanks for the fix. 107149-receipt-issue-fixed-04.mp4 |
Reviewer Checklist
Screenshots/VideosAndroid: HybridApp107149-android-hybrid-001.mp4Android: mWeb Chrome107149-mweb-chrome-001.mp4iOS: HybridAppCould not test due to build issues. I think this is fine since this issue is not platform dependent. iOS: mWeb Safari107149-mweb-safari-001.mp4MacOS: Chrome / Safari107149-web-chrome-001.mp4 |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.53-0 🚀
|
|
No help site update needed — this PR fixes failed expense requests overwriting newer edits or receipts, restoring expected behavior without adding a workflow or making existing article instructions incorrect. |
|
🚀 Deployed to production by https://github.com/arosiclair in version: 9.5.53-3 🚀
Bundle Size Analysis (Sentry): |
1 similar comment
|
🚀 Deployed to production by https://github.com/arosiclair in version: 9.5.53-3 🚀
Bundle Size Analysis (Sentry): |

Explanation of Change
When an expense request fails, its failure data was a copy of the whole expense taken when the request was queued. Requests run one at a time and their optimistic data shows up right away, so by the time an earlier request fails the user may have changed the expense again. Writing back the old copy erased those newer changes, most visibly a new receipt or description.
This is the first of two PRs for this issue. Failure data now undoes only the fields the failed request wrote, so changes made while it was pending survive.
Implementation details
getTransactionRevertValues(transaction, optimisticTransaction)returns the queue-time values of the fields the optimistic MERGE changed, going into nested objects (comment,receipt), withnullfor keys the request added. Request state (pendingFields,pendingAction,errorFields,errors) is still set by each caller. Two cases are handled on purpose:modifiedWaypoints, is removed whole. An empty object left behind would be read as set, somodifiedWaypoints ?? comment.waypointswould return no waypoints.completeSplitBill), nothing is reverted, same as before. Otherwise every written field would look new and get removed.UpdateMoneyRequest.ts: the shared edit builder, the tracked-expense builder and the Search snapshot use it. The explicitreportID: transaction?.reportIDis dropped from the failure data, since the helper already restoresreportIDwhen the edit changed it.Split.ts(completeSplitBill): uses it, soiouRequestTypeand themodified*fields the request added are removed on failure.Receipt.ts(detachReceipt): restores onlyreceipt.DeleteMoneyRequest.ts: failure is a MERGE of{pendingAction: null}instead of a SET of the old copy. The old copy brought back pending fields that an earlier, already finished edit had cleared, so the expense stayed pending forever.TrackExpense.tsandMergeTransaction.ts: the expense is removed optimistically, so the failure data still SETs the old copy, now withpendingActionandpendingFieldscleared.Fixed Issues
$ #106957
PROPOSAL:
Tests
Both edits fail:
mainthe amount stays at the failed value.With the Troubleshoot toggle, each request's failure is applied as soon as it fails. When the server returns an error instead, the failure is applied only after all pending requests have finished, so the values revert at that point.
Regular edits still work:
Offline tests
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Both requests fail, before the fix: the expense ends at PLN 42.00, an amount the server never accepted, with nothing pending:
3290-before-fix-both-fail.mp4
Both requests fail, after the fix: the expense ends at PLN 99.00 with the original description, which is what the server has:
3290-after-fix-both-fail.mp4