Skip to content

Quantity and total in a row of the "Unapproved card" search is wrong #84235

Closed

Description

@mitarachim

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: v9.3.31-1
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #83567
Email or phone of affected tester (no customers): applausetester+ag040326@applause.expensifail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Windows 11/ Chrome, iPhone 13 Mini/ iOS 26.3
App Component: Search

Action Performed:

Precondition: Have a company card feed added, and assign a card to any workspace member.

  1. Navigate to https://staging.new.expensify.com/
  2. Go to workspace chat
  3. Go to the expense report with the card transactions
  4. Move some transactions to a new report
  5. Delete the report created in step 4
  6. Go to Reports > Unapproved card

Expected Result:

The quantity in the "Expenses" column should be 5, and the Total should be $4,078.50

Actual Result:

The quantity in the "Expenses" column is equal to 3 when the expenses shown after expanding the row are 5.
The Total displayed is $3,078.50

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7094204_1772671474144.83562-Web.mp4

View all open jobs on GitHub

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    DeployBlockerIndicates it should block deploying the API
    on Mar 5, 2026
  2. melvin-bot commented on Mar 5, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #83567

  3. melvin-bot commented on Mar 5, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. melvin-bot commented on Mar 5, 2026

    @melvin-bot

    Triggered auto assignment to @joekaufmanexpensify (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.

  5. github-actions commented on Mar 5, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  6. OSBotify commented on Mar 5, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Backend bug
    Causing PR: #83567 - "Add unreported status to unapproved cards" by @JS00001 (High confidence)
    Related Issues: #83562 (original issue that PR 83567 was fixing)

    Recommendation: REVERT

    PR #83567 added UNREPORTED status to the Unapproved Card search query. While the frontend change itself is correct (it allows unreported card transactions to appear in the search), it has exposed a backend bug where the API returns incorrect aggregated count and total values for card groups when unreported transactions are included.

    The issue is only reproducible on staging (not production), confirming that PR #83567 introduced or exposed this regression.

    Labels: Removing DeployBlockerCash label since this is a backend bug. The DeployBlocker label should remain to block the backend/Web deploy until the API aggregation logic is fixed.

    Detailed Analysis

    Evidence

    Verification

    PR #83567 modified src/libs/SearchUIUtils.ts line 762 to add CONST.SEARCH.STATUS.EXPENSE.UNREPORTED to the status filter for the Unapproved Card suggested search.

    Root Cause

    The issue is in the backend API, not the App code:

    1. SearchCardGroup type (in src/types/onyx/SearchResults.ts) defines count and total fields that come from the backend API
    2. CardListItemHeader component displays these values directly from the API response
    3. When PR Add unreported status to unapproved cards #83567 added UNREPORTED status to the query, the backend API began including unreported transactions in the results
    4. However, the backend is incorrectly calculating the aggregated count and total for card groups when unreported transactions are present

    The frontend correctly displays what the backend returns - the bug is that the backend API is returning wrong aggregated values for card groups containing unreported transactions.

    Why this is a backend bug:

    • The App PR only changed the search query parameters (which statuses to include)
    • The aggregation logic that calculates count and total happens on the backend/API
    • The frontend has no way to fix incorrect aggregated values returned by the API
    • The fix needs to happen in the backend code that processes Search API requests and calculates group aggregations
  7. MelvinBot commented on Mar 5, 2026

    @MelvinBot
    Contributor

    🔍 Issue Analysis

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

    When viewing the "Unapproved card" search (which groups expenses by card), the collapsed card group row shows the wrong count (3 instead of 5) and wrong total ($3,078.50 instead of $4,078.50). However, expanding the row correctly displays all 5 transactions. This started happening after PR #83567 added the UNREPORTED status to the "Unapproved card" search filter.

    What is the root cause of that problem?

    The root cause is a server-side aggregation mismatch. Here's the evidence chain:

    1. The count and total are computed on the server, not the client. The API returns pre-aggregated count and total fields inside SearchCardGroup objects (keyed with group_ prefix in the response). The client code in getCardSections() (src/libs/SearchUIUtils.ts:2445-2492) simply spreads ...cardGroup directly from the API response — no client-side recalculation.

    2. The header renders these server values verbatim. CardListItemHeader (src/components/SelectionListWithSections/Search/CardListItemHeader.tsx:101-119) renders String(cardItem.count) and TotalCell({ total: cardItem.total }) directly.

    3. The expanded view uses a separate API call that works correctly. When a user expands a card group, buildSpecificGroupQuery() (src/libs/SearchUIUtils.ts:2381-2386) builds a new flat query that keeps status=[unreported, drafts, outstanding], removes groupBy, and adds cardID=X. This flat query correctly returns all 5 individual transactions.

    4. The discrepancy is between the server's GROUP BY aggregation and the flat query. The backend's GROUP BY aggregation (which computes count/total for each card group) is not properly including UNREPORTED transactions in its calculation. The flat individual-transaction query does include them. This is why the collapsed header shows 3/$3,078.50 while expanding shows 5/$4,078.50.

    PR #83567 changed the client-side search query to include UNREPORTED status (src/libs/SearchUIUtils.ts:765), but the server-side GROUP BY aggregation code path was likely not updated to account for this new status in its totals computation.

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

    This requires a server-side fix. The backend search handler that processes groupBy=card queries needs to include transactions with UNREPORTED status in its GROUP BY aggregation (count and total computation). The server-side code that generates SearchCardGroup entries should use the same status filter criteria for both:

    • The GROUP BY aggregation (count/total per card)
    • The individual transaction listing (when the group is expanded)

    The App (client) code is working correctly — it faithfully displays what the server returns and correctly passes the status=[unreported, drafts, outstanding] filter in the search query.

    What alternative solutions did you explore? (Optional)

    Client-side workaround (not recommended): The client could recalculate count/total from the expanded transactions after they are loaded. However, this would only fix the numbers after expansion, not on initial load, and would create inconsistency between the initial and post-expansion states. The proper fix is to correct the server-side aggregation.

    Reverting PR #83567 (temporary mitigation): If an immediate fix is needed for the deploy blocker, reverting the addition of UNREPORTED to the unapproved card search would restore consistent (but incomplete) behavior — the group count/total would match the displayed transactions, but UNREPORTED transactions would be excluded entirely. This was the original behavior before the fix for issue #83562.


    Next Steps for Contributor+ team: This is a server-side bug in the Search API's GROUP BY aggregation. The backend team should investigate the search endpoint's aggregation query to ensure it includes UNREPORTED status transactions when computing group-level count and total. Reply with @MelvinBot <your feedback> to refine this analysis.

  8. self-assigned this
    on Mar 5, 2026
  9. added and removed
    DeployBlockerIndicates it should block deploying the API
    on Mar 5, 2026
  10. JS00001 commented on Mar 5, 2026

    @JS00001
    Contributor

    Not a blocker, but PR open to fix

  11. luacmartins commented on Mar 6, 2026

    @luacmartins
    Contributor

    PR merged and deployed.

  12. luacmartins commented on Mar 6, 2026

    @luacmartins
    Contributor

    We can close this one

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions