Skip to content

[$250] Cannot delete unreported expense in bulk from new dot #85484

Closed

Description

@m-natarajan

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.3.37-10
Reproducible in staging?: Needs Reproduction (Unable to reproduce)
Reproducible in production?: Needs Reproduction
If this was caught during regression testing, add the test name, ID and link from BrowserStack:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @Tmjarnesk1
Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. Navigate to Reports > Expenses
  2. Apply filters for unreported expense
  3. Select more than 1 expense,
  4. Cilck on the bulk select dropdown and observe the options

Expected Result:

Option to delete the expense displayed

Actual Result:

No option to delete the expense, but displayed in Classic for same expenses

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

The screenshot for the issue is in Slack thread

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @truph01
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022033684018846889884
  • Upwork Job ID: 2033684018846889884
  • Last Price Increase: 2026-03-16

Activity

  1. added
    Daily
    Bug
    on Mar 16, 2026
  2. MelvinBot commented on Mar 16, 2026

    @MelvinBot
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When selecting multiple unreported expenses in Reports > Expenses and opening the bulk action dropdown, the "Delete" option is not shown. This option is available in Classic for the same expenses.

    What is the root cause of that problem?

    The root cause is in canDeleteMoneyRequestReport at App/src/libs/ReportUtils.ts:3102-3117. This function correctly identifies unreported transactions (isUnreported = true when transaction.reportID === '0'), but the ownership check always fails for them.

    Here's the logic flow:

    1. shouldShowDeleteOption in SearchUIUtils.ts:4608-4651 is called for each selected transaction
    2. For unreported expenses (reportID = '0'), it looks up report_actions_0 in search results — which doesn't exist since report ID '0' is a synthetic placeholder
    3. It calls canDeleteMoneyRequestReport(undefined, [transaction], []) with an empty report actions array
    4. Inside canDeleteMoneyRequestReport, ownership is determined by: getIOUActionForTransactionID(reportActions, transactionID)?.actorAccountID === currentUserAccountID
    5. With an empty array, getIOUActionForTransactionID returns undefined, so isOwner = false
    6. The function returns isOwner && canCardTransactionBeDeleted → false

    The fundamental problem: unreported transactions don't have IOU report actions (since they aren't on any report), but the ownership check requires one to determine who created the transaction. There's no fallback ownership mechanism for unreported expenses.

    An existing unit test at SearchUIUtilsTest.ts:7109 passes by manually providing reportAction in mock data, which masks this real-world behavior where the search API doesn't include report actions for reportID '0'.

    What changes do you think we should make in order to solve the problem?

    In canDeleteMoneyRequestReport at ReportUtils.ts:3115-3116, add an alternative ownership check for unreported transactions. When isUnreported is true and no report action is available to determine ownership, fall back to checking the transaction's ownerAccountID (which is set from the report action's actorAccountID or the report's ownerAccountID during search result processing) against the current user's account ID. This ensures unreported expenses created by the current user can be deleted.

    The same pattern should be mirrored in shouldShowDeleteOption in SearchUIUtils.ts where the parentReportAction fallback is constructed — ensuring that for unreported transactions, ownership can be established via selectedTransactions[id].ownerAccountID when no report action is available.

    What alternative solutions did you explore? (Optional)

    1. Backend fix: Have the search API include synthetic IOU report actions for unreported transactions keyed under report_actions_0. This was rejected as it would require backend changes for what is fundamentally a frontend ownership-check limitation, and adding fake report actions could have unintended side effects elsewhere.

    2. Skip ownership check entirely for unreported expenses: Since unreported expenses are always owned by the current user (they haven't been submitted to anyone else), we could skip the isOwner check when isUnreported is true. However, this is less safe than explicitly verifying ownership via an alternative field.


    Detailed Investigation

    Key Code Locations

    • shouldShowDeleteOption — SearchUIUtils.ts:4608-4651: Gates whether the delete bulk action appears. For expense type queries, iterates selected transactions and calls canDeleteMoneyRequestReport.

    • canDeleteMoneyRequestReport — ReportUtils.ts:3102-3117: The ownership check (isOwner) relies on getIOUActionForTransactionID finding a matching IOU report action. For unreported expenses, no such action exists.

    • getIOUActionForTransactionID — ReportActionsUtils.ts:2523-2528: Searches an array of report actions for one matching the transaction ID. Returns undefined when called with an empty array.

    • useSearchBulkActions — useSearchBulkActions.ts:1130-1140: The hook that builds bulk action options. Delete is only added when shouldShowDeleteOption returns true.

    • createReportActionsLookupMaps — SearchUIUtils.ts:1579-1617: Builds the moneyRequestReportActionsByTransactionID map from search data. For unreported transactions, this map has no entries since no report_actions_0 key exists.

    Evidence Chain

    Search API response → createReportActionsLookupMaps (no entries for reportID '0') → TransactionListItemType.reportAction = undefined → selectedTransactions[id].reportAction = undefined → shouldShowDeleteOption passes empty array to canDeleteMoneyRequestReport → getIOUActionForTransactionID([]) returns undefined → isOwner = false → canDeleteMoneyRequestReport returns false → delete option hidden


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  3. added
    External
    on Mar 16, 2026
  4. added
    Help Wanted
    on Mar 16, 2026
  5. melvin-bot commented on Mar 16, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @truph01 (External)

  6. melvin-bot commented on Mar 16, 2026

    @melvin-bot
  7. changed the title [-]Cannot delete unreported expense in bulk from new dot[/-] [+][$250] Cannot delete unreported expense in bulk from new dot[/+] on Mar 16, 2026
  8. shengxinzhe commented on Mar 17, 2026

    @shengxinzhe

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When selecting multiple unreported expenses in Reports > Expenses and using the bulk action dropdown, the "Delete" option is missing. This option is available in Classic for the same expenses.

    What is the root cause of that problem?

    The bug is in canDeleteMoneyRequestReport at ReportUtils.ts:3104-3119. The ownership check at line 3107 always fails for unreported transactions because no IOU report actions exist for reportID = '0'.

    Here is the exact failure chain:

    1. shouldShowDeleteOption in SearchUIUtils.ts:4665-4678 iterates each selected transaction
    2. For unreported expenses, parentReportID = transaction.reportID is '0' (the UNREPORTED_REPORT_ID constant)
    3. currentSearchResults?.["report_actions_0"] is undefined — the search API has no report actions for the synthetic report ID '0'
    4. parentReportAction resolves to undefined, so canDeleteMoneyRequestReport receives an empty array [] for reportActions
    5. Inside canDeleteMoneyRequestReport at line 3107:
      const isOwner = transactionID
        ? getIOUActionForTransactionID(reportActions, transactionID)?.actorAccountID === currentUserAccountID
        : false;
      getIOUActionForTransactionID([]) returns undefined, so isOwner = (undefined === currentUserAccountID) → false
    6. At line 3115-3118, isUnreported = true (since transaction.reportID === '0'), and the function returns isOwner && canCardTransactionBeDeleted → false && true → false
    7. Since shouldShowDeleteOption requires every() selected transaction to pass, a single unreported expense hides the Delete button for the entire selection

    The fundamental issue: the ownership check relies exclusively on IOU report actions, which do not exist for unreported expenses (they have no parent report or report actions by definition).

    What changes do you think we should make in order to solve the problem?

    Single-line fix in canDeleteMoneyRequestReport at ReportUtils.ts:3117-3118.

    Change:

    if (isUnreported) {
        return isOwner && canCardTransactionBeDeleted;
    }

    To:

    if (isUnreported) {
        return canCardTransactionBeDeleted;
    }

    Why removing the isOwner guard is safe for unreported expenses:

    1. Unreported expenses (reportID = '0') are personal — they have not been submitted to any report or approver
    2. The search API only returns a user's own unreported expenses; there is no admin or delegate path that surfaces another user's unreported transactions
    3. The canCardTransactionBeDeleted check already guards against deleting corporate card transactions with the wrong liability type, which is the meaningful safety check for unreported expenses
    4. The existing ownership check via IOU report actions is designed for reported expenses where admin/delegate access makes ownership verification necessary — this invariant does not apply to unreported expenses

    What alternative solutions did you explore? (Optional)

    1. Add ownerAccountID fallback from Transaction type: Not viable — the Transaction type (src/types/onyx/Transaction.ts) does not have an ownerAccountID field. The SelectedTransactionInfo.ownerAccountID is populated from item.reportAction?.actorAccountID (Search/index.tsx:144, 773), which is undefined for unreported transactions (since reportAction itself is undefined). So any fallback to transaction.ownerAccountID would also resolve to undefined.

    2. Construct synthetic report action in shouldShowDeleteOption: Creating a fake IOU action with actorAccountID = currentUserAccountID to pass to canDeleteMoneyRequestReport would work mechanically, but introduces a code smell — manufacturing test data to satisfy an ownership check that should not apply in the first place.

    3. Pass ownerAccountID as additional parameter: Modifying canDeleteMoneyRequestReport's signature to accept a fallback ownerAccountID adds unnecessary complexity to a function used across many call sites, when the simpler approach of recognizing that unreported expenses are self-owned is both correct and complete.

  9. melvin-bot commented on Mar 17, 2026

    @melvin-bot

    📣 @shengxinzhe! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  10. shengxinzhe commented on Mar 17, 2026

    @shengxinzhe

    Contributor details
    Your Expensify account email: shengyu_0830@163.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~0173a64078113c2de8

  11. melvin-bot commented on Mar 17, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  12. 30 remaining items

  13. melvin-bot commented on Apr 15, 2026

    @melvin-bot

    @truph01 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  14. melvin-bot commented on Apr 17, 2026

    @melvin-bot

    @truph01 Eep! 4 days overdue now. Issues have feelings too...

  15. melvin-bot commented on Apr 21, 2026

    @melvin-bot

    @truph01 Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

  16. melvin-bot commented on Apr 23, 2026

    @melvin-bot

    @truph01 10 days overdue. Is anyone even seeing these? Hello?

  17. added
    Weekly
    and removed
    Daily
    on Apr 28, 2026
  18. melvin-bot commented on Apr 28, 2026

    @melvin-bot

    This issue has not been updated in over 14 days. @truph01 eroding to Weekly issue.

  19. added and removed
    Weekly
    on May 21, 2026
  20. melvin-bot commented on May 21, 2026

    @melvin-bot

    This issue has not been updated in over 15 days. @truph01 eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  21. melvin-bot commented on Jun 1, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  22. melvin-bot commented on Jul 20, 2026

    @melvin-bot

    @truph01, this Monthly task hasn't been acted upon in 6 weeks; closing.

    If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead.

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

Metadata

Metadata

Assignees

Labels

BugExternalHelp WantedMonthlyNot a priorityReviewing

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions