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-10-01] [$250] Search - Error occurs after adding "group-by: reports" to the search query #89168
Version Number: v9.3.64-13 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: EDGE case. Issue to retest: #62222
Internal issue: https://github.com/Expensify/Expensify/issues/507014 Email or phone of affected tester (no customers): N/A Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Windows 11 / Chrome, iPhone 13 / iOS 26.5, Samsung Galaxy A52 / Android 14 App Component: Search
Action Performed:
Preconditions:
Logged in to a user that has some expenses
Steps:
1.Go to Spend > Expense
Click advance filters
Select From an account that you're logged in (yourself) > save the search > click view results
Go to search bar
Add query in the existing input "group-by: reports" and ente
Click advance filters and select save
Expected Result:
typing "group-by: reports" should show expected result and "from" filter remains applied
Actual Result:
Error occurs after adding "group-by: reports" to the search query and "from" filter disappear
"reports" is not a valid groupBy value. The valid values are defined in CONST.SEARCH.GROUP_BY: from, card, withdrawal-id, category, merchant, tag, month, week, year, quarter. The PEG parser accepts any identifier as a groupBy value without validation, so group-by:reports passes parsing but fails downstream.
The from filter disappears because of the substitution map flow. When a user edits the search bar text, getUpdatedSubstitutionsMap re-parses the query with the autocomplete parser on every keystroke. If the parser produces incorrect or empty ranges during intermediate typing states (e.g. while typing group-by: with no value yet), it returns {} for the substitution map (line 24-26), wiping the from display-name-to-accountID mapping. When the query is subsequently submitted, the from display name can't be substituted back to an accountID, and buildFilterFormValuesFromQuery filters it out because personalDetails?.[displayName] returns undefined.
What changes do you think we should make in order to solve the problem?
Two fixes:
Validate groupBy values at parse time or submission time. In getQueryWithUpdatedValues, after parsing the query, check if queryJSON.groupBy is a valid CONST.SEARCH.GROUP_BY value. If not, strip it from the query (or show a user-facing error) rather than submitting an invalid value that causes downstream failures.
Prevent the substitution map from being fully wiped. In getUpdatedSubstitutionsMap, when searchAutocompleteQueryRanges.length === 0, return the existing substitutions instead of {}. If the autocomplete parser fails to produce ranges for a partially-typed query, we should preserve the existing substitutions rather than discarding them, so that the from filter mapping survives editing.
What alternative solutions did you explore? (Optional)
Restricting the PEG grammar to only accept valid groupBy values would catch invalid input earlier, but the grammar is also used for autocomplete suggestions, and being too restrictive there creates a poor UX for partial/in-progress typing.
Wrapping the autocomplete parse() call in a try/catch in getUpdatedSubstitutionsMap and returning the previous substitutions on failure would be more defensive but doesn't address the root cause of "reports" being invalid.
Investigation details
Data flow that triggers the bug:
User has a search with from:12345 (displayed as from:"John Doe" via the substitution map)
User types group-by: reports in the search bar
During typing, getUpdatedSubstitutionsMap re-parses the query — at intermediate states (e.g., just group-by: with no value), the autocomplete parser may return zero ranges, causing the substitution map to be wiped to {}
On submit, getQueryWithSubstitutions can't find "John Doe" → 12345 mapping, so the display name is submitted as-is
buildFilterFormValuesFromQuery filters from values through personalDetails?.[id] — since the display name isn't a valid key, the from filter is silently removed
Additionally, groupBy:"reports" is sent to the backend API, which may return an error since "reports" is not in the valid enum
Possibly related issue:Expensify/App#89588 — "The app crashes after selecting a group on the search page" — may share underlying group-by handling issues.
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.
Please re-state the problem that we are trying to solve in this issue.
When a user adds group-by: reports to the existing search query (for example to a saved search filtered by From: yourself) and then clicks the Save button to open the Save search page, an error occurs and the displayed filters look wrong. The value reports is not a recognized group-by value (the recognized values are from, card, withdrawal-id, category, merchant, tag, month, week, year, quarter), so the unrecognized value flows through the rest of the search code and breaks rendering on the Save search page.
What is the root cause of that problem?
The Peggy search grammar treats groupBy as a defaultKey and accepts any value the user types — there is no validation that the value belongs to CONST.SEARCH.GROUP_BY. The grammar rule and root key list are here:
So after parsing group-by:reports, the resulting queryJSON.groupBy ends up with the literal string "reports". Most downstream code is defensive about that (for example getValidGroupBy returns undefined for unknown values):
But the Save search page and the Display popup pass the raw value directly to translate() to look up the localized label, without going through getValidGroupBy. The Save search page does this when building the list of applied displays:
Because there is no search.filters.groupBy.reports translation key (only the keys for the recognized values exist), translate() cannot resolve the path. In production and staging that triggers a Log.alert(...) call that surfaces as the error the user sees, and on development builds it throws and the React tree falls back to an error boundary which is what makes the existing from chip and the rest of the previously rendered filters appear to "disappear" along with the rest of the page content.
The translation lookup itself is here for reference:
thrownewError(`${path} was not found in the ${locale} locale`);
}
What changes do you think we should make in order to solve the problem?
Validate group-by values once, at the boundary where the parsed query is materialized, instead of patching every consumer. The natural place to do this is getCachedSearchQueryJSON in SearchQueryUtils.ts, which is the function that turns the parser output into the cached SearchQueryJSON object that everything else consumes:
console.error(`Error when parsing SearchQuery: "${query}"`,e);
}
}
After the parser produces result and before the object is frozen and cached, we will check whether result.groupBy is one of the values listed in CONST.SEARCH.GROUP_BY. If it is not, we will set result.groupBy to undefined. We will also clear result.view in the same branch when there is no longer a valid groupBy, because the rest of the code already treats view as meaningful only when a groupBy is set (for example buildSearchQueryString only emits view: in the URL when queryJSON?.groupBy is truthy, and buildFilterFormValuesFromQuery only writes the form view field when queryJSON.groupBy is set), so dropping view here keeps the cached object internally consistent.
We will also remove the corresponding groupBy (and, for consistency, view when it gets dropped) entries from result.rawFilterList if the parser stored them there as default raw filters. That list is what buildUserReadableQueryString walks to produce the human-readable query string shown in the search input, via formatDefaultRawFilterSegment:
Without that cleanup the search input would still display group-by:reports even after we drop the field from the rest of the JSON, which would be confusing.
After this single normalization step, all downstream consumers — the Save search page, the Display popup, the Advanced Filters form, the URL builder, the hash computation in getQueryHashes, and so on — will see groupBy as either undefined or one of the recognized values, and the translate(search.filters.groupBy.${value}) calls become safe by construction. The rest of the user's filters (such as from) are kept intact because we are only touching the unrecognized root-level field, not the flat filter list.
What alternative solutions did you explore? (Optional)
Validate at every consumer that calls translate(search.filters.groupBy.${value}). This works but is more invasive (Save search page, Display popup, and any future consumer would need the same guard) and is easy to forget when adding new code paths, which is how this bug appeared in the first place.
Make the Peggy grammar reject unknown groupBy literals during parse. This would mean group-by:reports causes the whole query to fail to parse, and the search page would show a generic parse error instead of recovering and showing the user's other filters. Silently dropping the unknown value preserves the rest of the user's intent, which matches how the code already handles other unknown inputs (for example getValidGroupBy returning undefined).
Add a fallback string in translate() for missing keys instead of triggering Log.alert. That would mask this and other genuine missing-translation bugs across the app, so it is not appropriate for a search-specific issue.
changed the title [-]Search - Error occurs after adding "group-by: reports" to the search query[/-][+][$250] Search - Error occurs after adding "group-by: reports" to the search query[/+]on May 13, 2026
@truph01, This flow wasn’t covered in the original discussion. The original fix is working for the reported case, so we can address this additional flow in a follow-up PR or issue. Thanks.
26. @truph01, This flow wasn’t covered in the original discussion. The original fix is working for the reported case, so we can address this additional flow in a follow-up PR or issue. Thanks.
cc @jasperhuangg what do you think about it? I agree that they are two separate issues. If you think so, we can create a new issue with the reproduction steps in #89168 (comment)
It has the Bug and Daily labels and is assigned to trentpetty.
GitHub would not assign nabi-ebrahimi because they have not commented on the new issue yet. nabi-ebrahimi, please comment there so someone can assign you.
I did not add External. Add it if you want the usual Upwork job flow.
Activity
MelvinBot commentedon May 13, 2026
Proposal
What is the root cause of that problem?
There are two compounding issues:
"reports"is not a validgroupByvalue. The valid values are defined inCONST.SEARCH.GROUP_BY:from,card,withdrawal-id,category,merchant,tag,month,week,year,quarter. The PEG parser accepts any identifier as agroupByvalue without validation, sogroup-by:reportspasses parsing but fails downstream.The
fromfilter disappears because of the substitution map flow. When a user edits the search bar text,getUpdatedSubstitutionsMapre-parses the query with the autocomplete parser on every keystroke. If the parser produces incorrect or empty ranges during intermediate typing states (e.g. while typinggroup-by:with no value yet), it returns{}for the substitution map (line 24-26), wiping thefromdisplay-name-to-accountID mapping. When the query is subsequently submitted, thefromdisplay name can't be substituted back to an accountID, andbuildFilterFormValuesFromQueryfilters it out becausepersonalDetails?.[displayName]returns undefined.What changes do you think we should make in order to solve the problem?
Two fixes:
Validate
groupByvalues at parse time or submission time. IngetQueryWithUpdatedValues, after parsing the query, check ifqueryJSON.groupByis a validCONST.SEARCH.GROUP_BYvalue. If not, strip it from the query (or show a user-facing error) rather than submitting an invalid value that causes downstream failures.Prevent the substitution map from being fully wiped. In
getUpdatedSubstitutionsMap, whensearchAutocompleteQueryRanges.length === 0, return the existingsubstitutionsinstead of{}. If the autocomplete parser fails to produce ranges for a partially-typed query, we should preserve the existing substitutions rather than discarding them, so that thefromfilter mapping survives editing.What alternative solutions did you explore? (Optional)
groupByvalues would catch invalid input earlier, but the grammar is also used for autocomplete suggestions, and being too restrictive there creates a poor UX for partial/in-progress typing.parse()call in a try/catch ingetUpdatedSubstitutionsMapand returning the previous substitutions on failure would be more defensive but doesn't address the root cause of"reports"being invalid.Investigation details
Data flow that triggers the bug:
from:12345(displayed asfrom:"John Doe"via the substitution map)group-by: reportsin the search bargetUpdatedSubstitutionsMapre-parses the query — at intermediate states (e.g., justgroup-by:with no value), the autocomplete parser may return zero ranges, causing the substitution map to be wiped to{}getQueryWithSubstitutionscan't find"John Doe"→12345mapping, so the display name is submitted as-isbuildFilterFormValuesFromQueryfiltersfromvalues throughpersonalDetails?.[id]— since the display name isn't a valid key, thefromfilter is silently removedgroupBy:"reports"is sent to the backend API, which may return an error since"reports"is not in the valid enumPossibly related issue: Expensify/App#89588 — "The app crashes after selecting a group on the search page" — may share underlying group-by handling issues.
Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.melvin-bot commentedon May 13, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @truph01 (
External)wildan-m commentedon May 13, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user adds
group-by: reportsto the existing search query (for example to a saved search filtered byFrom: yourself) and then clicks the Save button to open the Save search page, an error occurs and the displayed filters look wrong. The valuereportsis not a recognizedgroup-byvalue (the recognized values arefrom,card,withdrawal-id,category,merchant,tag,month,week,year,quarter), so the unrecognized value flows through the rest of the search code and breaks rendering on the Save search page.What is the root cause of that problem?
The Peggy search grammar treats
groupByas adefaultKeyand accepts any value the user types — there is no validation that the value belongs toCONST.SEARCH.GROUP_BY. The grammar rule and root key list are here:App/src/libs/SearchParser/searchParser.peggy
Line 313 in c300f98
The valid values are defined here:
App/src/CONST/index.ts
Lines 7587 to 7598 in c300f98
So after parsing
group-by:reports, the resultingqueryJSON.groupByends up with the literal string"reports". Most downstream code is defensive about that (for examplegetValidGroupByreturnsundefinedfor unknown values):App/src/libs/SearchUIUtils.ts
Lines 4411 to 4413 in c300f98
But the Save search page and the Display popup pass the raw value directly to
translate()to look up the localized label, without going throughgetValidGroupBy. The Save search page does this when building the list of applied displays:App/src/pages/Search/SearchSavePage.tsx
Lines 96 to 98 in c300f98
The Display popup does the same when rendering the Group by row:
App/src/components/Search/FilterDropdowns/DisplayPopup.tsx
Line 87 in c300f98
Because there is no
search.filters.groupBy.reportstranslation key (only the keys for the recognized values exist),translate()cannot resolve the path. In production and staging that triggers aLog.alert(...)call that surfaces as the error the user sees, and on development builds it throws and the React tree falls back to an error boundary which is what makes the existingfromchip and the rest of the previously rendered filters appear to "disappear" along with the rest of the page content.The translation lookup itself is here for reference:
App/src/libs/Localize/index.ts
Lines 117 to 139 in c300f98
What changes do you think we should make in order to solve the problem?
Validate
group-byvalues once, at the boundary where the parsed query is materialized, instead of patching every consumer. The natural place to do this isgetCachedSearchQueryJSONinSearchQueryUtils.ts, which is the function that turns the parser output into the cachedSearchQueryJSONobject that everything else consumes:App/src/libs/SearchQueryUtils.ts
Lines 592 to 642 in c300f98
After the parser produces
resultand before the object is frozen and cached, we will check whetherresult.groupByis one of the values listed inCONST.SEARCH.GROUP_BY. If it is not, we will setresult.groupBytoundefined. We will also clearresult.viewin the same branch when there is no longer a validgroupBy, because the rest of the code already treatsviewas meaningful only when agroupByis set (for examplebuildSearchQueryStringonly emitsview:in the URL whenqueryJSON?.groupByis truthy, andbuildFilterFormValuesFromQueryonly writes the formviewfield whenqueryJSON.groupByis set), so droppingviewhere keeps the cached object internally consistent.We will also remove the corresponding
groupBy(and, for consistency,viewwhen it gets dropped) entries fromresult.rawFilterListif the parser stored them there as default raw filters. That list is whatbuildUserReadableQueryStringwalks to produce the human-readable query string shown in the search input, viaformatDefaultRawFilterSegment:App/src/libs/SearchQueryUtils.ts
Lines 1646 to 1704 in c300f98
Without that cleanup the search input would still display
group-by:reportseven after we drop the field from the rest of the JSON, which would be confusing.After this single normalization step, all downstream consumers — the Save search page, the Display popup, the Advanced Filters form, the URL builder, the hash computation in
getQueryHashes, and so on — will seegroupByas eitherundefinedor one of the recognized values, and thetranslate(search.filters.groupBy.${value})calls become safe by construction. The rest of the user's filters (such asfrom) are kept intact because we are only touching the unrecognized root-level field, not the flat filter list.Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/89168-search-groupby-validation?expand=1
Result
Kapture.2026-05-23.at.13.51.31.mp4
What alternative solutions did you explore? (Optional)
translate(search.filters.groupBy.${value}). This works but is more invasive (Save search page, Display popup, and any future consumer would need the same guard) and is easy to forget when adding new code paths, which is how this bug appeared in the first place.groupByliterals during parse. This would meangroup-by:reportscauses the whole query to fail to parse, and the search page would show a generic parse error instead of recovering and showing the user's other filters. Silently dropping the unknown value preserves the rest of the user's intent, which matches how the code already handles other unknown inputs (for examplegetValidGroupByreturningundefined).translate()for missing keys instead of triggeringLog.alert. That would mask this and other genuine missing-translation bugs across the app, so it is not appropriate for a search-specific issue.melvin-bot commentedon May 13, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022054389470496700909
[-]Search - Error occurs after adding "group-by: reports" to the search query[/-][+][$250] Search - Error occurs after adding "group-by: reports" to the search query[/+]179 remaining items
mallenexpensify commentedon Oct 8, 2026
@truph01 👀 above plz
truph01 commentedon Oct 9, 2026
@nabi-ebrahimi Could you check it?
nabi-ebrahimi commentedon Oct 9, 2026
@truph01, This flow wasn’t covered in the original discussion. The original fix is working for the reported case, so we can address this additional flow in a follow-up PR or issue. Thanks.
melvin-bot commentedon Oct 12, 2026
@mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
truph01 commentedon Oct 13, 2026
cc @jasperhuangg what do you think about it? I agree that they are two separate issues. If you think so, we can create a new issue with the reproduction steps in #89168 (comment)
mallenexpensify commentedon Oct 13, 2026
@jasperhuangg 👀 above, if you agree, want to ask @MelvinBot to create an issue and assign @truph01 and @nabi-ebrahimi ?
melvin-bot commentedon Oct 14, 2026
@jasperhuangg Eep! 4 days overdue now. Issues have feelings too...
melvin-bot commentedon Oct 16, 2026
@jasperhuangg 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
jasperhuangg commentedon Oct 16, 2026
Yeah happy with that direction. @MelvinBot can you create an issue?
MelvinBot commentedon Oct 16, 2026
I created Search - Error and From filter dropped after entering "group-by: reports" on a saved search (follow-up to #89168). It uses the regression test steps and QA's staging v9.5.6-0 video.
BugandDailylabels and is assigned totrentpetty.nabi-ebrahimibecause they have not commented on the new issue yet.nabi-ebrahimi, please comment there so someone can assign you.External. Add it if you want the usual Upwork job flow.view run
mallenexpensify commentedon Oct 16, 2026
Reckon we can close now.. right?
garrettmknight commentedon Oct 19, 2026
$250 approved for @truph01