[$250] Spend - The card accruals tab shows no results even though there are unapproved expenses
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: Reproducible in staging?: Needs Reproduction (Reproduction blocked) Reproducible in production?: Needs Reproduction (Reproduction blocked) 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: @GeoVasile Slack conversation (hyperlinked to channel name): #expensify_bugs
Action Performed:
Prerequisites: Needs account with card accruals
- Log in Expensify (admin account)
- Go to Spend > Card accruals
- Enter desired filters (or leave automatically applied) and see the results
Expected Result:
Should show all unapproved expenses in that date range
Actual Result:
The page is empty with a "Nothing to show" message
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
- [x] Windows: Chrome
- [ ] MacOS: Chrome / Safari
Screenshots/Videos
For the details, check please the OP
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022113573170296652599
- Upwork Job ID: 2113573170296652599
- Last Price Increase: 2026-11-25
Issue Owner
Current Issue Owner: @mukhrr
⚠️ Preliminary analysis (low confidence) — treat as a starting point, not a conclusion.
I think the Card accruals tab is empty because its default query searches only one card feed. If the admin's unapproved card expenses are on a different feed, the search returns nothing.
The query is type:expense group-by:card feed:<one feed> status:unreported,drafts,outstanding (SearchSuggestionUtils.ts:333-343). The feed is activeExpensifyCardFeedID ?? defaultFeedID (SearchSuggestionUtils.ts:152). Since Default Card accruals to the active workspace's Expensify Card, the active workspace's Expensify Card wins whenever it exists (useCardFeedsForDisplay.ts:76-103). It never checks which feed actually has unapproved spend. So expenses on a company/bank feed, or on another workspace's Expensify Card, are excluded.
I wasn't able to verify this because reproduction is blocked and the issue doesn't say which feed the reporter's expenses are on. To confirm, check:
- Which
feed:value is in the Card accruals query on the affected account (click the search bar or check theSearchrequest'sjsonQuery). - Whether the unapproved expenses are on that same feed. If they aren't, this is the cause.
- Whether the reporter added date filters (for example, posted vs. date) that also exclude the expenses.
If confirmed, the fix is a product decision: drop the feed filter from the default query, or include every eligible feed instead of one.
Ruled out
- Feed ID format mismatch: the Expensify Card feed ID (
<fundID>_Expensify Card, CardFeedUtils.ts:171) is the same format the Statements search already uses. - Client-side filtering: card groups are only dropped when
cardIDis missing (SearchUIUtils.ts:3263-3283), so an empty page means the server returned nothing for the query. - Automatic date range: the default query adds no date filter.
Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @FitseTLT (External)
Job added to Upwork: https://www.upwork.com/jobs/~022113573170296652599
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Spend > Card accruals, the tab displays "Nothing to show" and returns no results even when there are unapproved card expenses present on the account.
What is the root cause of that problem?
There are two primary factors causing this issue in src/libs/SearchSuggestionUtils.ts:
-
Empty String Fallback in Default Query Serialization: In
src/libs/SearchSuggestionUtils.ts(lines 338-343), the query forCONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARDis constructed via:searchQuery: buildQueryStringFromFilterFormValues({ type: CONST.SEARCH.DATA_TYPES.EXPENSE, feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : [''], groupBy: CONST.SEARCH.GROUP_BY.CARD, status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING], }),When
unapprovedCardFeedIDisundefined(e.g. workspace without an active Expensify Card or beforedefaultFeedIDresolves), the ternary falls back to['']. InbuildQueryStringFromFilterFormValues, passing an empty string array results in generating a malformed or empty feed filter (feed:), which causes the backend search parser to fail to match any expenses, returning an empty result set. -
Single-Feed Restriction on Multi-Feed Card Accruals: In line 152 of
SearchSuggestionUtils.ts:const unapprovedCardFeedID = activeExpensifyCardFeedID ?? defaultFeedID;Card accruals represent all unapproved card expenses awaiting approval across an admin's managed cards. Enforcing a strict single-feed filter (
unapprovedCardFeedID) isolates the query to only one specific card feed. If an admin has unapproved expenses on company card feeds (e.g. Visa/Mastercard commercial feeds) or on other workspace cards, they are completely excluded from the search result.
What changes do you think we should make in order to solve the problem?
1. In src/libs/SearchSuggestionUtils.ts:
- Omit the
feedfilter whenunapprovedCardFeedIDis not present, instead of passing['']:
[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD]: {
key: CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD,
translationPath: 'search.tabs.unapprovedCard',
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
icon: 'CreditCardHourglass',
searchQuery: buildQueryStringFromFilterFormValues({
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
...(unapprovedCardFeedID ? {feed: [unapprovedCardFeedID]} : {}),
groupBy: CONST.SEARCH.GROUP_BY.CARD,
status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
}),
// ...
}
When unapprovedCardFeedID is not provided (or when viewing all unapproved card spend grouped by card), omitting the feed parameter allows the search query (type:expense groupBy:card status:unreported,drafts,outstanding) to correctly query all unapproved card expenses across the user's cards.
- Alternatively, if the product requirement is to support all active card feeds when multiple exist, pass the array of eligible feed IDs from
useCardFeedsForDisplayrather than narrowing strictly toactiveExpensifyCardFeedID ?? defaultFeedID.
2. In src/libs/SearchQueryUtils.ts:
In buildQueryStringFromFilterFormValues, sanitize the feed array by filtering out empty or whitespace-only strings (filter(feed => feed?.trim())) so that empty string elements are never serialized into search queries.
What alternative solutions did you explore? (Optional)
- MelvinBot's analysis: MelvinBot identified the feed restriction but did not address the fallback bug where
feed: ['']emits an empty filter parameter that breaks search resolution, and did not supply a concrete code diff. - Dropping
groupBy: card: Unnecessary and undesired, as Card accruals specifically requires grouping results by card entity.
What automated tests can you add to prevent this from re-occurring?
In tests/unit/SearchSuggestionUtilsTest.ts:
- Verify
UNAPPROVED_CARDquery generation whenunapprovedCardFeedIDis undefined: ensure the resulting query string does not containfeed:or empty feed tokens. - Verify that when
unapprovedCardFeedIDis valid, it is correctly serialized into thefeed:<id>syntax alongsidegroup-by:card. - Verify that
buildQueryStringFromFilterFormValuesstrips empty string items from thefeedfilter array.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01b60d704ba377be83
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01963a583fd60b304f
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Spend > Card accruals, navigating to the tab shows "Nothing to show" and returns zero results, even when there are unapproved card expenses present in that date range.
What is the root cause of that problem?
There are two compounding bugs in query construction and serialization:
1. Bogus Empty-String Fallback in SearchSuggestionUtils.ts:
In src/libs/SearchSuggestionUtils.ts (lines 338-343):
[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD]: {
key: CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD,
translationPath: 'search.tabs.unapprovedCard',
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
icon: 'CreditCardHourglass',
searchQuery: buildQueryStringFromFilterFormValues({
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : [''],
groupBy: CONST.SEARCH.GROUP_BY.CARD,
status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
}),
When unapprovedCardFeedID is undefined (for instance, when an admin navigates to Card accruals on a workspace without an active Expensify Card or before card feeds are fetched), the ternary expression explicitly falls back to [''] (an array containing a single empty string) instead of undefined.
2. Query Serializer Emits Dangling feed: Filter in SearchQueryUtils.ts:
In src/libs/SearchQueryUtils.ts (lines 1537-1546), buildQueryStringFromFilterFormValues checks:
Array.isArray(filterValue) && filterValue.length > 0
Because [''].length === 1, this condition evaluates to true.
The sanitizer then serializes [''], resulting in a malformed dangling syntax token:
type:expense status:unreported,drafts,outstanding groupBy:card feed:
When sent to the backend search engine, feed: matches an empty feed identifier (which matches 0 expenses), completely suppressing all unapproved card expenses and rendering "Nothing to show".
Additionally, when an organization has card expenses on company bank feeds (Plaid / commercial card feeds) or multiple feeds, restricting the query strictly to a single activeExpensifyCardFeedID ?? defaultFeedID causes expenses on other company card feeds to be omitted when filtered.
What changes do you think we should make in order to solve the problem?
We should implement a clean, two-part fix:
1. Caller Fix in src/libs/SearchSuggestionUtils.ts:
Do not inject [''] when unapprovedCardFeedID is undefined. Only supply feed when a valid feed ID exists:
searchQuery: buildQueryStringFromFilterFormValues({
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
...(unapprovedCardFeedID ? {feed: [unapprovedCardFeedID]} : {}),
groupBy: CONST.SEARCH.GROUP_BY.CARD,
status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
}),
When unapprovedCardFeedID is omitted, the query evaluates to type:expense status:unreported,drafts,outstanding groupBy:card, which correctly aggregates all unapproved card expenses across the account grouped by card.
2. Defensive Serializer Guard in src/libs/SearchQueryUtils.ts:
In buildQueryStringFromFilterFormValues (line 1540), sanitize array filter values by filtering out empty or whitespace-only strings before generating the query syntax:
const filterValueArray = [...new Set<string>(filterValue.filter((val): val is string => typeof val === 'string' && val.trim().length > 0))];
if (filterValueArray.length === 0) {
return undefined;
}
This ensures that even if any caller passes empty string values in an array filter (for feed, policyID, from, etc.), buildQueryStringFromFilterFormValues will never emit dangling filter keys (feed:, policyID:) that break backend search query execution.
What alternative solutions did you explore? (Optional)
- Only fixing
SearchSuggestionUtils.ts: LeavingSearchQueryUtils.tsunpatched leaves the query generator vulnerable whenever filter forms or URL queries contain empty array elements. - Dropping
groupBy: card: Not viable, as Card accruals specifically requires grouping by card entity.
What automated tests can you add to prevent this from re-occurring?
In tests/unit/SearchQueryUtilsTest.ts:
- Verify that
buildQueryStringFromFilterFormValuesstrips empty string elements from array filters (e.g.,{feed: ['']}) and does not emit danglingfeed:in the query string. - Verify that valid feed filters (
{feed: ['12345_Expensify Card']}) are properly serialized asfeed:"12345_Expensify Card".
In tests/unit/SearchSuggestionUtilsTest.ts:
- Verify that
getSuggestedSearchescreatesUNAPPROVED_CARDsearch query withoutfeed:whenunapprovedCardFeedIDisundefined. - Verify that when
unapprovedCardFeedIDis provided, it is correctly included in theUNAPPROVED_CARDsearch query.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
What is the root cause of that problem?
The Card accruals query is scoped to one feed. In getSuggestedSearches (src/libs/SearchSuggestionUtils.ts, UNAPPROVED_CARD) it is feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : [''], with unapprovedCardFeedID = activeExpensifyCardFeedID ?? defaultFeedID (line ~152). SearchQueryProvider.tsx passes defaultCardFeed?.id (getDefaultCardFeed in useCardFeedsForDisplay.ts returns .at(0) of one policy's feeds) and activeExpensifyCardFeedID, which wins whenever the active workspace has an Expensify Card. The tab shows if any workspace qualifies, but expenses on any other feed are filtered out, hence "Nothing to show". The [''] fallback is not the cause: Statements uses the same sentinel on purpose.
What changes do you think we should make in order to solve the problem?
- In
useCardFeedsForDisplay.ts, returnunapprovedCardFeedIDs:activeExpensifyCardFeedIDplus every id inObject.values(cardFeedsByPolicy).flat()(already computed there), de-duplicated. - In
SearchQueryProvider.tsx, pass it togetSuggestedSearchesinstead ofactiveExpensifyCardFeedID. - In
getSuggestedSearches, usefeed: unapprovedCardFeedIDs?.length ? unapprovedCardFeedIDs : defaultFeedID ? [defaultFeedID] : [''].feedis already an array filter. - In
tests/unit/SearchSuggestionUtilsTest.ts: two feed IDs both appear in theUNAPPROVED_CARDquery; no IDs falls back todefaultFeedID, then to[''].
What alternative solutions did you explore? (Optional)
- MelvinBot says to drop the feed filter or include all feeds but gives no diff; this is that diff, from data the hook already has.
- camesenin and pranav440 remove the
['']fallback. That path only runs with no feed, would change Statements, and still leaves one feed for admins who have several. - Dropping
group-by:card: not viable.
Proposal
Please re-state the problem that we are trying to solve in this issue.
In the Spend tab under To-do, clicking Card accruals shows no results even though the workspace has unapproved card expenses (and the Card accruals suggestion tab itself is visible in the left navigation).
What is the root cause of that problem?
There is a mismatch between the policy/feed eligibility logic that decides whether to show the Card accruals suggestion (src/libs/SearchUIUtils.ts:740-804) and the feed-resolution logic that builds its search query (src/hooks/useCardFeedsForDisplay.ts:21-129, src/components/Search/SearchQueryProvider.tsx:66-73, and src/libs/SearchSuggestionUtils.ts:144-153, 333-343):
- Visibility checks all policies with
(isAdmin || isAuditor) && isApprovalEnabled, butgetActiveExpensifyCardFeedIDonly checksactivePolicyID: Insrc/libs/SearchUIUtils.ts:777,shouldShowUnapprovedCardSuggestionistruewhenever any workspace inpoliciessatisfies:
However, inisPaidPolicy && (isAdmin || isAuditor) && isApprovalEnabled && (hasCardFeed || !!defaultExpensifyCard)src/hooks/useCardFeedsForDisplay.ts:76-129(added in PR #97262),getActiveExpensifyCardFeedIDonly checkspolicies?.[${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}]. IfactivePolicyIDisundefined, points to a personal/different workspace, or points to a workspace whereapprovalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL,activeExpensifyCardFeedIDreturnsundefined. defaultCardFeedignores(isAdmin || isAuditor) && isApprovalEnabledand overwritesdefaultExpensifyCard: Insrc/components/Search/SearchQueryProvider.tsx:70-72andsrc/hooks/useSearchTypeMenuSections.ts:116,defaultFeedIDis passed asdefaultCardFeed?.id ?? defaultExpensifyCard?.id. Insrc/hooks/useCardFeedsForDisplay.ts:21-28,eligiblePoliciesSelectorused bygetDefaultCardFeedonly checkspolicy?.areCompanyCardsEnabled— it never checksisPaidGroupPolicy(policy),(isAdmin || isAuditor), orisApprovalEnabled! As a result:defaultCardFeedcan select a company card feed from a workspace where approvals are disabled or where the user is only a member, causingbuildFeedQuery(activeExpensifyCardFeedID ?? defaultFeedID)insrc/libs/SearchSuggestionUtils.ts:149to query the wrong feed (feed:"...") and return zero results.- Even within a single eligible workspace that has both a company card feed and Expensify Cards (or across multiple eligible workspaces),
activeExpensifyCardFeedID ?? defaultFeedIDonly passes a single feed ID instead of the eligible feeds that triggeredshouldShowUnapprovedCardSuggestion.
What changes do you think we should make in order to solve the problem?
Align the feed resolution for UNAPPROVED_CARD with the exact policy/feed eligibility criteria used in src/libs/SearchUIUtils.ts:740-804:
- In
src/hooks/useCardFeedsForDisplay.ts, computeunapprovedCardFeedIDs(or eligible accrual feeds) using the same policy eligibility predicate asSearchUIUtils.ts:777:- A policy is eligible for Card accruals when
isPaidGroupPolicy(policy) && (policy.role === CONST.POLICY.ROLE.ADMIN || policy.role === CONST.POLICY.ROLE.AUDITOR)andgetApprovalWorkflow(policy) !== CONST.POLICY.APPROVAL_MODE.OPTIONAL. - If
activePolicyIDrefers to an eligible policy that has at least one card feed (Expensify Card settings withidinallExpensifyCardSettingsor a company card feed incardFeedsByPolicy[activePolicyID]), collect the feed IDs foractivePolicyID; otherwise, collect the feed IDs across all eligible policies (matchingshouldShowUnapprovedCardSuggestioninSearchUIUtils.ts).
- A policy is eligible for Card accruals when
- In
src/libs/SearchSuggestionUtils.ts(buildFeedQueryandgetSuggestedSearches), acceptunapprovedCardFeedIDs: string[]:- Update
buildFeedQuery(feedIDs?: string[])to emitfeed:${feedIDs.map((id) =>"${id}").join(',')}whenfeedIDs.length > 0, so the Card accruals query includes the eligible Expensify Card and/or company card feeds for the target workspace(s) and never falls back to a feed from an ineligible workspace.
- Update
- Pass
unapprovedCardFeedIDsfromuseCardFeedsForDisplayinsrc/components/Search/SearchQueryProvider.tsxandsrc/hooks/useSearchTypeMenuSections.ts.
What alternative solutions did you explore? (Optional)
- Only adding a fallback inside
getActiveExpensifyCardFeedIDwhenactivePolicyIDhas no Expensify Card: That still breaks whendefaultCardFeedcomes from a workspace where approvals are disabled or the user is not an Admin/Auditor, or when an eligible workspace has both an Expensify Card feed and a company card feed. Filtering by the same eligibility predicate asSearchUIUtils.tsresolves all of these cases consistently.
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Spend > Card accruals (under the To-do section), clicking Card accruals displays "Nothing to show" even though the workspace has unapproved card expenses and the Card accruals suggestion tab is visible in the left navigation.
What is the root cause of that problem?
In src/libs/SearchSuggestionUtils.ts (lines 145-153 and 333-343), the UNAPPROVED_CARD (Card accruals) suggested search builds its query with a single feed parameter:
https://github.com/Expensify/App/blob/c08c85f3c5d20214e219dd1a1286936a513527cc/src/libs/SearchSuggestionUtils.ts#L150-L153
https://github.com/Expensify/App/blob/c08c85f3c5d20214e219dd1a1286936a513527cc/src/libs/SearchSuggestionUtils.ts#L333-L343
const unapprovedCardFeedID = activeExpensifyCardFeedID ?? defaultFeedID;
...
[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD]: {
key: CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD,
translationPath: 'search.tabs.unapprovedCard',
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
icon: 'CreditCardHourglass',
searchQuery: buildQueryStringFromFilterFormValues({
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : [''],
groupBy: CONST.SEARCH.GROUP_BY.CARD,
status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
}),
Meanwhile, in src/components/Search/SearchPageHeader/SearchTypeMenu.tsx / src/libs/SearchUIUtils.ts (createTypeMenuSections), the Card accruals menu item is shown whenever the user is an admin of any policy with a card feed (shouldShowUnapprovedCard), and SearchQueryProvider computes activeExpensifyCardFeedID and defaultFeedID (getDefaultCardFeed in src/hooks/useCardFeedsForDisplay.ts), which:
- Prioritizes
activeExpensifyCardFeedID(the active workspace's Expensify Card feed) even if that feed has zero unapproved expenses while a company card feed (or another workspace's Expensify Card feed) has unapproved expenses, or - Falls back to
feed: [''](feed:"") whenunapprovedCardFeedIDisundefined(for example, while card feeds are still loading or whendefaultCardFeeddoes not resolve a feed key), which serializes an invalid emptyfeed:""filter that matches zero transactions on the backend.
What changes do you think we should make in order to solve the problem?
- Resolve
activeExpensifyCardFeedID/defaultFeedIDacross eligible admin policies and avoid serializingfeed: ['']insrc/libs/SearchSuggestionUtils.ts:- In
src/hooks/useCardFeedsForDisplay.ts/SearchQueryProvider, ensure that if the active policy does not have an Expensify Card feed (or is not an admin policy with card feeds),unapprovedCardFeedIDfalls back to an admin-eligible card feed (consistent withcreateTypeMenuSectionsinsrc/libs/SearchUIUtils.ts). - In
src/libs/SearchSuggestionUtils.ts(lines 296and338), omitfeedwhenunapprovedCardFeedID/defaultFeedIDisundefined(...(unapprovedCardFeedID && {feed: [unapprovedCardFeedID]})) rather than passing['']so the query never serializes a brokenfeed:""token.
- In
📣 @xian96xx! 📣 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:
- Make sure you've read and understood the contributing guidelines.
- 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.
- 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.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~016c1aa34b51059d42
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Spend > Card accruals (under the To-do section), clicking Card accruals displays "Nothing to show" even though the workspace has unapproved card expenses and the Card accruals suggestion tab is visible in the left navigation.
What is the root cause of that problem?
In src/libs/SearchSuggestionUtils.ts (lines 333–343), the UNAPPROVED_CARD suggested search builds its query using buildQueryStringFromFilterFormValues:
[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD]: {
key: CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD,
translationPath: 'search.tabs.unapprovedCard',
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
icon: 'CreditCardHourglass',
searchQuery: buildQueryStringFromFilterFormValues({
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
feed: unapprovedCardFeedID ? [unapprovedCardFeedID] : [''],
groupBy: CONST.SEARCH.GROUP_BY.CARD,
status: [CONST.SEARCH.STATUS.EXPENSE.UNREPORTED, CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
}),
- When
unapprovedCardFeedID(computed asactiveExpensifyCardFeedID ?? defaultFeedID) isundefined(for instance, when card feeds are loading or when the active policy is not linked to an Expensify card feed), it passesfeed: ['']. - In
src/libs/SearchQueryUtils.ts(lines 1537–1540),buildQueryStringFromFilterFormValueshandles array filters:
BecauseArray.isArray(filterValue) && filterValue.length > 0['']haslength === 1, it serializesfeed:""(an empty string feed name filter). - Querying
feed:""forces the backend search to search exclusively for a card feed named""(empty string), matching zero expenses and rendering "Nothing to show". - The same issue exists in
CONST.SEARCH.SEARCH_KEYS.STATEMENTS(line 292), which also passesfeed: defaultFeedID ? [defaultFeedID] : [''].
What changes do you think we should make in order to solve the problem?
-
In
src/libs/SearchSuggestionUtils.ts:- For
UNAPPROVED_CARD(line 340), passfeed: unapprovedCardFeedID ? [unapprovedCardFeedID] : undefined(or conditionally include...(unapprovedCardFeedID ? {feed: [unapprovedCardFeedID]} : {})) instead of['']. - For
STATEMENTS(line 292), passfeed: defaultFeedID ? [defaultFeedID] : undefinedinstead of['']. Whenfeedis omitted, the query correctly searches unapproved expenses across all eligible card feeds without appending an invalidfeed:""constraint.
- For
-
In
src/libs/SearchQueryUtils.ts:- Inside
buildQueryStringFromFilterFormValues(line 1540), sanitize array values by filtering out empty/whitespace strings:
const filterValueArray = [...new Set<string>(filterValue)].filter((value) => value.trim().length > 0);This prevents any array filter (
feed,category,tag, etc.) from serializing empty string literals likefeed:""if empty strings ever enter form state. - Inside
What alternative solutions did you explore? (Optional)
Only fixing SearchQueryUtils.ts without cleaning up SearchSuggestionUtils.ts; however, fixing both at the suggestion builder and query serializer ensures complete consistency and protects all filter keys against empty token pollution.
Test Result / Verification:
- Open Spend > Card accruals with an account that has unapproved card expenses on a workspace/feed.
- Verify that clicking Card accruals opens the search query:
type:expense status:unreported,drafts,outstanding groupBy:card(or with the resolvedfeed:parameter). - Verify that the unapproved expenses are displayed grouped by card, rather than rendering "Nothing to show".
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal Update: Full Working Fix Verified & Branch Pushed
We have implemented and verified the fix on branch:
bhomvratrai-glitch:fix/104831-card-accruals-empty-feed-query
Commit: 1f275885
Summary of Changes
src/libs/SearchSuggestionUtils.ts:- For both
UNAPPROVED_CARDandSTATEMENTS, replaced the fallback['']withundefinedso that when a specific feed ID is not yet available/resolved, the query searches card expenses across all eligible card feeds without appending an invalidfeed:""filter.
- For both
src/libs/SearchQueryUtils.ts:- In
buildQueryStringFromFilterFormValues, added.filter((value) => value.trim().length > 0)on array filter values to guarantee that empty string tokens are never serialized into the query string.
- In
Ready to open the PR immediately upon milestone assignment!
@FitseTLT Whoops! This issue is 2 days overdue. Let's get this updated quick!
Not overdue
Proposal
Please re-state the problem that we are trying to solve in this issue.
When an admin opens Spend > Card accruals, the page displays an empty state even when unapproved card expenses exist on an eligible workspace card feed (as reproduced in #104831 (comment); separate from the backend domain-feed access gap tracked in Expensify/Expensify#662387).
What is the root cause of that problem?
On the App side, Card accruals (CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD) drops eligible card feeds in four places:
-
Tab visibility is multi-workspace, while the query picks a single feed: In
src/libs/SearchUIUtils.ts#L916,shouldShowUnapprovedCardSuggestionbecomestrueif any paid workspace where the user is anadmin,auditor, orcardAdminhas approvals enabled (approvalMode !== OPTIONAL) and at least one card feed exists. However,getSuggestedSearchesbuildsUNAPPROVED_CARDfrom a single ID:const unapprovedCardFeedID = activeExpensifyCardFeedID ?? defaultFeedID;When the active/default workspace has its own Expensify Card or company card feed with zero unapproved spend (e.g.,
Zed Feed),UNAPPROVED_CARDfilters strictly to that one feed and hides unapproved card expenses on the admin's other eligible workspace feeds (e.g.,Alpha Feed), or even on a second card feed within the same workspace. -
cardFeedsByPolicydrops configured CSV (ccupload*) feeds whose card list is not yet cached in Onyx: Insrc/hooks/useCardFeedsForDisplay.ts#L114,getCardFeedsForDisplayPerPolicy(allFeeds, translate, feedKeysWithCards, allPolicies)forwardsfeedKeysWithCardsintogetOriginalCompanyFeeds. Once any card list is hydrated in Onyx (feedKeysWithCardsis defined), lines999-1002filter out "gray zone" feeds (!isCustomFeed(key) && !isDirectFeed(key), which includes CSV upload feeds likeccupload1) whenevercards_<fundID>_<feed>has not been opened/fetched yet in that session. -
Unresolved feed fallback
['']emits a barefeed:token that corruptsstatus:: Insrc/libs/SearchSuggestionUtils.ts#L344-L349(andSTATEMENTSat line298), when no feed ID has resolved yet, passingfeed: ['']causesbuildQueryStringFromFilterFormValuesto emit a barefeed:token (feed: status:unreported,drafts,outstanding), which the search parser consumes as literal feed names instead of status filters. -
Saved
nvp_searchFilters.unapprovedCardkeeps the old auto-generated single-feed query across visits: Insrc/libs/SearchQueryUtils.ts#L3729-L3751,getValidLastQueryreturnslastQuerywhenever its filter keys matchdefaultQueryJSON. An existingunapprovedCardentry saved with a single auto-derivedfeed:<singleFeed>continues to override the updated multi-feed default query until the user manually resets filters.
What changes do you think we should make in order to solve the problem?
-
Share one policy-eligibility helper (
src/libs/SearchUIUtils.ts/src/libs/PolicyUtils.ts): ExtractisPolicyEligibleForCardAccruals(policy)(isPaidGroupPolicy(policy) && (ADMIN || AUDITOR || CARD_ADMIN) && approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL && pendingAction !== DELETE) and reuse it in bothgetSuggestedSearchesVisibilityand feed collection so tab visibility and default feed scope stay in lockstep. (Note on scope: if product decides in #104831 (comment) to scope only to the default workspace rather than all eligible workspaces, the same helper scopes toactivePolicywhile still including all Expensify Card + company/CSV feeds on that workspace.) -
Collect all eligible Expensify Card + ungated company/CSV feeds in
src/hooks/useCardFeedsForDisplay.ts#L114-L130:- Build
cardAccrualsFeedsByPolicy = getCardFeedsForDisplayPerPolicy(allFeeds, translate, undefined, allPolicies)(passingundefinedforfeedKeysWithCardsso configured CSV/company feeds inCardFeedUtils.ts#L364-L383are included even beforecards_<fundID>_<feed>is hydrated, while keepingcardFeedsByPolicyunchanged for display pickers). - For each policy passing
isPolicyEligibleForCardAccruals(ordered withactivePolicyIDfirst, then deterministically by policy/feed ID), collect its configured Expensify Card feed ID (reusinggetActiveExpensifyCardFeedIDprecedence) and itscardAccrualsFeedsByPolicy[policyID]feed IDs into a deduplicatedcardAccrualsFeedIDs: string[]. - Pass
cardAccrualsFeedIDsintogetSuggestedSearchesfrom bothsrc/components/Search/SearchQueryProvider.tsx#L71-L76andsrc/hooks/useSearchTypeMenuSections.ts#L69-L126->createTypeMenuSections.
- Build
-
Pass
cardAccrualsFeedIDsintoUNAPPROVED_CARDand eliminate barefeed:tokens (src/libs/SearchSuggestionUtils.ts&src/libs/SearchQueryUtils.ts):- In
getSuggestedSearchesandUNAPPROVED_CARD, acceptcardAccrualsFeedIDs?: string[], resolveconst resolvedCardAccrualsFeeds = cardAccrualsFeedIDs?.length ? cardAccrualsFeedIDs : (unapprovedCardFeedID ? [unapprovedCardFeedID] : []), and spread...(resolvedCardAccrualsFeeds.length > 0 && {feed: resolvedCardAccrualsFeeds})(doing the same forSTATEMENTSwhendefaultFeedIDis undefined). - In
buildQueryStringFromFilterFormValues, filter out empty/whitespace strings (filterValue.filter((v) => v.trim().length > 0)) so an empty array element can never emit a barefeed:prefix.
- In
-
Refresh stale single-feed defaults in
getValidLastQuery: WhensearchKey === CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD, iflastQueryJSONhas a positive single-feed filter that is a strict subset ofdefaultQueryJSON'sfeedlist and matches the old auto-derived feed (activeExpensifyCardFeedID ?? defaultFeedID), replacefeedwithdefaultQueryJSON'sfeedfilter while keeping non-feed filters (date,sortBy,sortOrder, negative exclusions) intact.
What alternative solutions did you explore? (Optional)
- Building the feed list from
cardFeedsByPolicydirectly:cardFeedsByPolicypassesfeedKeysWithCardsintogetOriginalCompanyFeeds, which silently drops configured CSV (ccupload*) feeds on non-default workspaces whenever another workspace's card list is already cached in Onyx. PassingundefinedforfeedKeysWithCardsin the accruals scope avoids that cache-dependent bug (verified in the After video below by clearingcards_23663815_ccupload1fromOnyxDBbefore opening Card accruals). - Omitting
feed:completely onUNAPPROVED_CARD: UnscopedgroupBy:cardcan pull in personal/unrelated card transactions; scoping explicitly tocardAccrualsFeedIDspreserves the intended workspace card boundary.
Demo (Before / After)
Test setup (staging.new.expensify.com): Admin of two Control workspaces with approvals enabled — default workspace has Zed Feed (0 unapproved expenses), second workspace has Alpha Feed (4 unapproved card expenses totaling TRY 13,106.88, with cards_23663815_ccupload1 cleared from OnyxDB and Zed Feed previously cached in nvp_searchFilters.unapprovedCard).
Before (main): Opening Spend > Card accruals queries only feed:23663851_ccupload1 (Feed: Zed Feed) and displays "No expenses to approve".
https://github.com/user-attachments/assets/9af11dce-81a1-49a2-89c9-e017284c3d23
After (with fix): Opening Spend > Card accruals (without pressing Reset) automatically resolves Feed: Alpha Feed, Zed Feed (feed:23663851_ccupload1,23663815_ccupload1) and displays all 4 unapproved card expenses (TRY 13,106.88).
https://github.com/user-attachments/assets/6aa03016-7d83-4e59-9966-cc551a087205
Hi @FitseTLT, friendly follow-up on this!
I have the verified surgical fix pushed to a clean branch: 👉 Compare Diff
It ensures that when unapprovedExpenses exist, the card accruals query parameters are properly sanitized and empty feed filters are omitted. Fully tested and ready for review!
REviewing soon
Will review tomorrow