You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-03-30] [$250] Expense - When workflows are disabled, deleting receipt shows unexpected error. #81493
Please re-state the problem that we are trying to solve in this issue.
When workflows are disabled, deleting receipt shows unexpected error.
What is the root cause of that problem?
The issue is that we allow removing a receipt from the report that is in status/state 2/2 and this seems to not be aligned with what BE expects. I assume that the backend is correct and not the front end, otherwise, the issue will have to be solved on the BE.
Because, I don't see a way to properly isolate this case on level of canEditFieldOfMoneyRequest. For example, if we target only fieldToEdit === CONST.EDIT_REQUEST_FIELD.RECEIPT, then you could forbid some other functionality related to receipts that you did not want to target.
What alternative solutions did you explore? (Optional)
N/A
Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.
Please re-state the problem that we are trying to solve in this issue.
When workflows are disabled on a workspace, deleting a receipt from an expense shows an "Unexpected error deleting this receipt" message. The delete button should either not appear, or the deletion should succeed.
What is the root cause of that problem?
When workflows are disabled, the policy's approvalMode is set to OPTIONAL (Submit & Close) and reimbursementChoice to REIMBURSEMENT_NO. Under these conditions, expense reports transition to CLOSED state (stateNum=2/APPROVED, statusNum=2/CLOSED) — either optimistically at creation time (via getExpenseReportStateAndStatus) or when the backend auto-processes them.
The frontend allows receipt deletion on CLOSED reports because of a gap in permission checks for admin/manager users:
canEditMoneyRequest returns true unconditionally for admin/manager users, bypassing the isClosedReport check that exists at line 4706 for regular requestors.
The restricted-field guard in canEditFieldOfMoneyRequest checks isSettled (statusNum=REIMBURSED/4) and isReportIDApproved (statusNum=APPROVED/3), but does not check isClosedReport (statusNum=CLOSED/2). Since CLOSED has a different statusNum than REIMBURSED or APPROVED, neither guard catches it.
So the delete button is shown, the user taps it, detachReceipt fires the DETACH_RECEIPT API call with no additional validation, the backend rejects it (because the report is CLOSED), and the failureData surfaces the "Unexpected error deleting this receipt" message.
Note: For non-admin requestors, the existing isClosedReport check at line 4706 already correctly blocks the delete button. The bug only manifests for users who are both an admin/manager AND the requestor.
What changes do you think we should make in order to solve the problem?
if (isSettled(String(moneyRequestReport.reportID)) || isReportIDApproved(String(moneyRequestReport.reportID))) {
Proposed:
if (isSettled(String(moneyRequestReport.reportID)) || isReportIDApproved(String(moneyRequestReport.reportID)) || isClosedReport(moneyRequestReport)) {
This is consistent with how isSettled and isReportIDApproved already work — all three represent terminal report states where restricted fields (including RECEIPT) should not be editable. The isClosedReport function is already defined and used elsewhere in the same file.
What alternative solutions did you explore? (Optional)
The existing proposal from imadirtydog suggests adding !isClosedReport(transactionReport) to shouldShowDeleteReceiptButton in TransactionReceiptModalContent.tsx. While that would fix the delete button visibility in that specific component, fixing it at the canEditFieldOfMoneyRequest level in ReportUtils.ts is more robust because:
It fixes the root cause rather than patching one UI consumer
It protects ALL restricted fields (not just RECEIPT) from being editable on closed reports
Any other code that calls canEditFieldOfMoneyRequest with RECEIPT also gets the fix automatically
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.
[Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment:
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion:
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue:
Regression Test Proposal
Precondition:
Test:
Log in as a workspace admin
Go to workspace settings → More features → Disable workflows
Go to LHN → Open workspace chat
Create a manual expense with a camera image, entering a merchant name. Then submit it.
Open the expense → Tap the receipt image → Tap the 3-dot menu
Verify the "Delete receipt" option is not shown (previously it was shown and caused an unexpected error)
Activity
imadirtydog commentedon Feb 5, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When workflows are disabled, deleting receipt shows unexpected error.
What is the root cause of that problem?
The issue is that we allow removing a receipt from the report that is in status/state 2/2 and this seems to not be aligned with what BE expects. I assume that the backend is correct and not the front end, otherwise, the issue will have to be solved on the BE.
Basically, the issue is that
App/src/pages/media/AttachmentModalScreen/routes/TransactionReceiptModalContent.tsx
Line 83 in edcc677
What changes do you think we should make in order to solve the problem?
I think solution should be made on the level of this component
App/src/pages/media/AttachmentModalScreen/routes/TransactionReceiptModalContent.tsx
Line 86 in edcc677
Because, I don't see a way to properly isolate this case on level of canEditFieldOfMoneyRequest. For example, if we target only fieldToEdit === CONST.EDIT_REQUEST_FIELD.RECEIPT, then you could forbid some other functionality related to receipts that you did not want to target.
The change to be made:
What alternative solutions did you explore? (Optional)
N/A
Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.
melvin-bot commentedon Mar 5, 2026
Triggered auto assignment to @CortneyOfstad (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.MelvinBot commentedon Mar 5, 2026
🔍 Issue Analysis
Please re-state the problem that we are trying to solve in this issue.
When workflows are disabled on a workspace, deleting a receipt from an expense shows an "Unexpected error deleting this receipt" message. The delete button should either not appear, or the deletion should succeed.
What is the root cause of that problem?
When workflows are disabled, the policy's
approvalModeis set toOPTIONAL(Submit & Close) andreimbursementChoicetoREIMBURSEMENT_NO. Under these conditions, expense reports transition to CLOSED state (stateNum=2/APPROVED,statusNum=2/CLOSED) — either optimistically at creation time (viagetExpenseReportStateAndStatus) or when the backend auto-processes them.The frontend allows receipt deletion on CLOSED reports because of a gap in permission checks for admin/manager users:
canEditMoneyRequestreturnstrueunconditionally for admin/manager users, bypassing theisClosedReportcheck that exists at line 4706 for regular requestors.The restricted-field guard in
canEditFieldOfMoneyRequestchecksisSettled(statusNum=REIMBURSED/4) andisReportIDApproved(statusNum=APPROVED/3), but does not checkisClosedReport(statusNum=CLOSED/2). Since CLOSED has a different statusNum than REIMBURSED or APPROVED, neither guard catches it.The RECEIPT-specific check has no closed-report guard either.
So the delete button is shown, the user taps it,
detachReceiptfires theDETACH_RECEIPTAPI call with no additional validation, the backend rejects it (because the report is CLOSED), and the failureData surfaces the "Unexpected error deleting this receipt" message.Note: For non-admin requestors, the existing
isClosedReportcheck at line 4706 already correctly blocks the delete button. The bug only manifests for users who are both an admin/manager AND the requestor.What changes do you think we should make in order to solve the problem?
Add
isClosedReport(moneyRequestReport)to the restricted-field guard atApp/src/libs/ReportUtils.ts:4821:Current:
Proposed:
This is consistent with how
isSettledandisReportIDApprovedalready work — all three represent terminal report states where restricted fields (including RECEIPT) should not be editable. TheisClosedReportfunction is already defined and used elsewhere in the same file.What alternative solutions did you explore? (Optional)
The existing proposal from
imadirtydogsuggests adding!isClosedReport(transactionReport)toshouldShowDeleteReceiptButtoninTransactionReceiptModalContent.tsx. While that would fix the delete button visibility in that specific component, fixing it at thecanEditFieldOfMoneyRequestlevel inReportUtils.tsis more robust because:canEditFieldOfMoneyRequestwith RECEIPT also gets the fix automaticallyNext Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.30 remaining items
melvin-bot commentedon Mar 30, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
melvin-bot commentedon Mar 30, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
mallenexpensify commentedon Mar 30, 2026
@truph01 I'm planning to apply the 50% regression penalty here cuz of
Comment with reasoning if you disagree.
Also, plz complete the BZ checklist and tag me in a post once you have. Thx
truph01 commentedon Mar 31, 2026
@mallenexpensify Based on #85669 (comment), #85669 isn't a regression from my PR.
truph01 commentedon Mar 31, 2026
BugZero Checklist:
[Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment:
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion:
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue:
Regression Test Proposal
Precondition:
Test:
Do we agree 👍 or 👎
Zapier Logs
Run ID: 00040eee-8a6c-acd5-3123-41dd5ebfab44truph01 commentedon Mar 31, 2026
@mallenexpensify I completed checklist
mallenexpensify commentedon Apr 1, 2026
Payment Summary
Contributor+: @truph01 due $250 via NewDot
^ Test case created. thx
m-natarajan commentedon Apr 1, 2026
@truph01 This is regarding the regression test proposal
Delete receipt option is displayed, Is this flow changed or Am I missing anything here?
Recording.2632.mp4
truph01 commentedon Apr 2, 2026
@m-natarajan It should be:
I've updated regression test.
garrettmknight commentedon May 10, 2026
$250 approved for @truph01