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
[$250] Search - Tags from another workspace are displayed when filtering by workspace #84239
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Please re-state the problem that we are trying to solve in this issue.
When a user filters search results by a specific workspace and then opens the Tags filter, tags from all workspaces are displayed instead of only tags from the selected workspace.
What is the root cause of that problem?
In SearchFiltersTagPage, when building the tagItems list, there is a condition that falls back to showing tags from ALL policies when selectedPoliciesTagLists is empty. The problem is that selectedPoliciesTagLists is only populated when policyIDs (from the search filters form) is non-empty. However, even when a workspace IS selected in the search bar (via workspace: prefix in the query), the policyID field in the advanced filters form may not reflect that selection — so selectedPoliciesTagLists ends up empty and the fallback path runs, pulling tags from every policy.
The fallback at line 42 is too broad: it iterates over all values of allPolicyTagLists with no workspace restriction, so every tag from every workspace the user belongs to gets included.
What changes do you think we should make in order to solve the problem?
The fix is to derive the active policy filter from the current search query (not just the advanced filters form policyID field) and use it when narrowing tags. The searchAdvancedFiltersForm already has a policyID array — we need to make sure this is read correctly AND that when policyID is populated, the fallback path is skipped entirely. Additionally, the condition guarding the fallback should be tightened: if the user has explicitly selected a workspace (policyID is non-empty), we should show an empty list rather than fall back to all tags.
The key change is replacing the condition !selectedPoliciesTagLists || selectedPoliciesTagLists.length === 0 with policyIDs.length === 0. The old condition was true whenever a selected policy happened to have no tags, which caused the fallback to show all tags from all other workspaces. The new condition correctly checks whether the user has filtered by a workspace at all — if they have, we only show that workspace's tags (even if that list is empty); if they haven't, we show all tags across all workspaces.
What alternative solutions did you explore? (Optional)
Please re-state the problem that we are trying to solve in this issue.
When a user searches with a specific workspace filter (e.g. workspace:MyWorkspace), then opens Filters > Tags, tags from all workspaces are displayed instead of only tags from the selected workspace. This is especially noticeable when the selected workspace has no tags — the user sees tags from other workspaces that shouldn't appear.
What is the root cause of that problem?
In SearchFiltersTagPage.tsx, the code builds a list of tags to display. On line 30, it reads policyIDs from the filter form. On lines 32-35, it filters allPolicyTagLists to only the selected workspace's tags (selectedPoliciesTagLists).
if (!selectedPoliciesTagLists || selectedPoliciesTagLists.length === 0) {
This condition conflates two different scenarios:
No workspace selected → policyIDs is [] → selectedPoliciesTagLists is [] → showing all tags is correct
Workspace selected but has no tags → policyIDs is ['ABC123'] → selectedPoliciesTagLists is [] → should show no tags, but the fallback incorrectly shows all tags from all workspaces
The condition checks whether the result is empty rather than whether a workspace filter was applied, so it always falls through to the "show everything" path when the selected workspace has no tags.
What changes do you think we should make in order to solve the problem?
In SearchFiltersTagPage.tsx, change the condition on line 41 from checking selectedPoliciesTagLists.length === 0 to checking policyIDs.length === 0. This way:
When no workspace is selected (policyIDs is empty) → show all tags (existing behavior, correct)
When a workspace is selected but has no tags (policyIDs is non-empty, selectedPoliciesTagLists is empty) → show no tags (fixed behavior)
The same fix should be applied to SearchFiltersCategoryPage.tsxline 63, which has the identical pattern with categories.
What alternative solutions did you explore? (Optional)
An alternative would be to pass the policyID as a navigation parameter to the tag filter page rather than relying on the Onyx form state. However, the current Onyx-based approach is the established pattern, and the fix only requires changing the conditional check — no architectural changes needed.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.
changed the title [-]Search - Tags from another workspace are displayed when filtering by workspace[/-][+][$250] Search - Tags from another workspace are displayed when filtering by workspace[/+]on Mar 5, 2026
📣 @soul5681! 📣
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:
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] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
No offending PR found, since this issue has existed for a long time and the initial feature didn’t cover this case.
[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: N/A
[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.
Regression Test Proposal
Precondition:
There are 2 workspaces (one workspace has added tags)
Test:
Go to Reports Tab
Click "Expenses" in the left sidebar
Click on the Search field
Type "workspace:" and Verify that you see autocomplete list for workspaces
Select the workspace without tags added
Click "Filters"
Go to the tags filter page
Verify Tags from another workspace should not appear in the list
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Activity
melvin-bot commentedon Mar 5, 2026
Triggered auto assignment to @JmillsExpensify (
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.MobileMage commentedon Mar 5, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user filters search results by a specific workspace and then opens the Tags filter, tags from all workspaces are displayed instead of only tags from the selected workspace.
What is the root cause of that problem?
In
SearchFiltersTagPage, when building thetagItemslist, there is a condition that falls back to showing tags from ALL policies whenselectedPoliciesTagListsis empty. The problem is thatselectedPoliciesTagListsis only populated whenpolicyIDs(from the search filters form) is non-empty. However, even when a workspace IS selected in the search bar (viaworkspace:prefix in the query), thepolicyIDfield in the advanced filters form may not reflect that selection — soselectedPoliciesTagListsends up empty and the fallback path runs, pulling tags from every policy.App/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx
Lines 41 to 45 in 058eee1
The fallback at line 42 is too broad: it iterates over all values of
allPolicyTagListswith no workspace restriction, so every tag from every workspace the user belongs to gets included.What changes do you think we should make in order to solve the problem?
The fix is to derive the active policy filter from the current search query (not just the advanced filters form
policyIDfield) and use it when narrowing tags. ThesearchAdvancedFiltersFormalready has apolicyIDarray — we need to make sure this is read correctly AND that whenpolicyIDis populated, the fallback path is skipped entirely. Additionally, the condition guarding the fallback should be tightened: if the user has explicitly selected a workspace (policyID is non-empty), we should show an empty list rather than fall back to all tags.App/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx
Lines 30 to 54 in 058eee1
const policyIDs = searchAdvancedFiltersForm?.policyID ?? []; const [allPolicyTagLists = getEmptyObject<NonNullable<OnyxCollection<PolicyTagLists>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS); const selectedPoliciesTagLists = Object.keys(allPolicyTagLists ?? {}) .filter((key) => policyIDs?.map((policyID) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`)?.includes(key)) ?.map((key) => getTagNamesFromTagsLists(allPolicyTagLists?.[key] ?? {})) .flat(); const tagItems = useMemo(() => { const items = [{name: translate('search.noTag'), value: CONST.SEARCH.TAG_EMPTY_VALUE as string}]; const uniqueTagNames = new Set<string>(); - if (!selectedPoliciesTagLists || selectedPoliciesTagLists.length === 0) { + if (policyIDs.length === 0) { const tagListsUnpacked = Object.values(allPolicyTagLists ?? {}).filter((item) => !!item); for (const tag of tagListsUnpacked.map(getTagNamesFromTagsLists).flat()) { uniqueTagNames.add(tag); } - } else { + } else if (selectedPoliciesTagLists.length > 0) { for (const tag of selectedPoliciesTagLists) { uniqueTagNames.add(tag); } } items.push(...Array.from(uniqueTagNames).map((tagName) => ({name: getCleanedTagName(tagName), value: tagName}))); return items; - }, [allPolicyTagLists, selectedPoliciesTagLists, translate]); + }, [allPolicyTagLists, policyIDs, selectedPoliciesTagLists, translate]);The key change is replacing the condition
!selectedPoliciesTagLists || selectedPoliciesTagLists.length === 0withpolicyIDs.length === 0. The old condition was true whenever a selected policy happened to have no tags, which caused the fallback to show all tags from all other workspaces. The new condition correctly checks whether the user has filtered by a workspace at all — if they have, we only show that workspace's tags (even if that list is empty); if they haven't, we show all tags across all workspaces.What alternative solutions did you explore? (Optional)
N/A
MelvinBot commentedon Mar 5, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user searches with a specific workspace filter (e.g.
workspace:MyWorkspace), then opens Filters > Tags, tags from all workspaces are displayed instead of only tags from the selected workspace. This is especially noticeable when the selected workspace has no tags — the user sees tags from other workspaces that shouldn't appear.What is the root cause of that problem?
In
SearchFiltersTagPage.tsx, the code builds a list of tags to display. On line 30, it readspolicyIDsfrom the filter form. On lines 32-35, it filtersallPolicyTagListsto only the selected workspace's tags (selectedPoliciesTagLists).The bug is on line 41:
This condition conflates two different scenarios:
policyIDsis[]→selectedPoliciesTagListsis[]→ showing all tags is correctpolicyIDsis['ABC123']→selectedPoliciesTagListsis[]→ should show no tags, but the fallback incorrectly shows all tags from all workspacesThe condition checks whether the result is empty rather than whether a workspace filter was applied, so it always falls through to the "show everything" path when the selected workspace has no tags.
What changes do you think we should make in order to solve the problem?
In
SearchFiltersTagPage.tsx, change the condition on line 41 from checkingselectedPoliciesTagLists.length === 0to checkingpolicyIDs.length === 0. This way:policyIDsis empty) → show all tags (existing behavior, correct)policyIDsis non-empty,selectedPoliciesTagListsis empty) → show no tags (fixed behavior)The same fix should be applied to
SearchFiltersCategoryPage.tsxline 63, which has the identical pattern with categories.What alternative solutions did you explore? (Optional)
An alternative would be to pass the policyID as a navigation parameter to the tag filter page rather than relying on the Onyx form state. However, the current Onyx-based approach is the established pattern, and the fix only requires changing the conditional check — no architectural changes needed.
Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.melvin-bot commentedon Mar 5, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @suneox (
External)[-]Search - Tags from another workspace are displayed when filtering by workspace[/-][+][$250] Search - Tags from another workspace are displayed when filtering by workspace[/+]melvin-bot commentedon Mar 5, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022029432897821585422
soul5681 commentedon Mar 5, 2026
🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.
melvin-bot commentedon Mar 5, 2026
📣 @soul5681! 📣
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:
Format:
24 remaining items
mallenexpensify commentedon Apr 7, 2026
Payment Summary
Contributor+: @suneox due $250 via NewDot on 2026-04-09
@suneox plz complete the BZ checklist and tag me in a post once you have. Thx
suneox commentedon Apr 9, 2026
BugZero Checklist:
No offending PR found, since this issue has existed for a long time and the initial feature didn’t cover this case.
[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: N/A
[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.
Regression Test Proposal
Precondition:
There are 2 workspaces (one workspace has added tags)
Test:
Verify Tags from another workspace should not appear in the list
Do we agree 👍 or 👎
melvin-bot commentedon Apr 16, 2026
@suneox Whoops! This issue is 2 days overdue. Let's get this updated quick!
suneox commentedon Apr 17, 2026
Not overdue, this issue is ready for payment I'll submit on ND soon
melvin-bot commentedon Apr 20, 2026
@suneox Whoops! This issue is 2 days overdue. Let's get this updated quick!
JmillsExpensify commentedon Apr 22, 2026
I created the regression test. Closing.
garrettmknight commentedon Apr 23, 2026
$250 approved for @suneox