Skip to content

[Due for payment 2026-06-29] [$250] Spend - Tag filter is present when account has no tag #93568

Closed

Description

@izarutskaya

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.4.7-1
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 https://github.com/Expensify/Expensify/issues/447655
Email or phone of affected tester (no customers): undefined
Issue reported by: Applause Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Create a new account.
  3. Create a workspace.
  4. Go to workspace settings > More features.
  5. Enable Tags.
  6. Go to workspace settings > Categories.
  7. Click More > Settings.
  8. Disable Members must categorize all expenses.
  9. Delete all the categories.
  10. Go to Spend > Expenses.
  11. Click Filters.
  12. Find Category and Tag filter

Expected Result:

Category and Tag filter should be hidden when account has no category and tag.

Actual Result:

When account has no category and tag, Category filter is hidden, but Tag filter is present.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7159815_1779379076130.2.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @daledah

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 15, 2026
  2. Ayesha-Ashraf-Dev commented on Jun 15, 2026

    @Ayesha-Ashraf-Dev

    🚨 Edited by proposal-police: This proposal was edited at 2026-06-15 10:00:38 UTC.

    Contributor details
    Your Expensify account email: ayeshaashraf0091@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/ayeshaa337

    Proposal

    [Updated]

    What is the root cause of that problem?

    The Tag filter's visibility is computed in useAdvancedSearchFilters.ts:341:

    const shouldDisplayTagFilter = shouldDisplayFilter(
        hasTags ? 1 : 0,
        policyDerived?.areTagsEnabled ?? false,
        !!selectedPolicyTagLists
    );

    The third argument (singlePolicyCondition) is !!selectedPolicyTagLists. But selectedPolicyTagLists comes from getAllPolicyValues, which always returns an array ([] at minimum) — so !!selectedPolicyTagLists is always true.

    Looking at shouldDisplayFilter:

    function shouldDisplayFilter(numberOfFilters, isFeatureEnabled, singlePolicyCondition = false) {
        return (numberOfFilters !== 0 || singlePolicyCondition) && isFeatureEnabled;
    }

    Because singlePolicyCondition is always true, the whole expression collapses to just areTagsEnabled. So the Tag filter shows whenever Tags is enabled, regardless of whether any tags actually exist.

    The Category filter does not have this bug because its equivalent condition correctly checks array length (line 340): selectedPolicyCategories?.length > 0. That is why Category is hidden after deletion but Tag is not.


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

    Replace the always-truthy !!selectedPolicyTagLists with a check that the selected policies actually contain tag entries, mirroring the Category filter's selectedPolicyCategories?.length > 0 pattern.

    In src/hooks/useAdvancedSearchFilters.ts:

    const hasSelectedPolicyTags = selectedPolicyTagLists.some((policyTagList) =>
        Object.values(policyTagList ?? {}).some(
            (tagList) => Object.keys(tagList.tags ?? {}).length > 0
        )
    );
    const shouldDisplayTagFilter = shouldDisplayFilter(
        hasTags ? 1 : 0,
        policyDerived?.areTagsEnabled ?? false,
        hasSelectedPolicyTags
    );

    This makes the Tag filter's singlePolicyCondition semantically match the Category filter's: show the filter only when tag entries actually exist in the selected policy.


    What alternative solutions did you explore? (Optional)

    Using selectedPolicyTagLists.length > 0 alone — a closer mirror to the Category line — is insufficient because a policy can have a tag-list container with zero tags inside it, so .length > 0 could still be true with no actual tags. Checking the nested tags content is more correct.

  3. melvin-bot commented on Jun 15, 2026

    @melvin-bot

    📣 @Ayesha-Ashraf-Dev! 📣
    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>
    
  4. MelvinBot commented on Jun 15, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    The Tag filter's visibility is computed in useAdvancedSearchFilters.ts:341:

    const shouldDisplayTagFilter = shouldDisplayFilter(hasTags ? 1 : 0, policyDerived?.areTagsEnabled ?? false, !!selectedPolicyTagLists);

    The third argument (singlePolicyCondition) is !!selectedPolicyTagLists. But selectedPolicyTagLists comes from getAllPolicyValues, which always returns an array ([] at minimum). An array — even an empty one — is always truthy, so !!selectedPolicyTagLists is always true.

    Looking at shouldDisplayFilter:

    function shouldDisplayFilter(numberOfFilters, isFeatureEnabled, singlePolicyCondition = false) {
        return (numberOfFilters !== 0 || singlePolicyCondition) && isFeatureEnabled;
    }

    Because singlePolicyCondition is always true, the whole expression collapses to just areTagsEnabled. So the Tag filter shows whenever the Tags feature is enabled, regardless of whether any tags actually exist — which is exactly the reported behavior (Tags enabled in step 5, no tags created → filter still shows).

    The Category filter does not have this bug because its equivalent condition correctly checks array length (line 340): selectedPolicyCategories?.length > 0. That's why Category is hidden but Tag is not.

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

    Replace the always-truthy !!selectedPolicyTagLists with a check that the selected policies actually contain tags, mirroring the existing hasTagsSelector logic.

    Suggested change in src/hooks/useAdvancedSearchFilters.ts
    const hasSelectedPolicyTags = selectedPolicyTagLists.some((policyTagList) =>
        Object.values(policyTagList ?? {}).some((tagList) => Object.keys(tagList.tags ?? {}).length > 0),
    );
    const shouldDisplayTagFilter = shouldDisplayFilter(hasTags ? 1 : 0, policyDerived?.areTagsEnabled ?? false, hasSelectedPolicyTags);

    This makes the Tag filter's singlePolicyCondition semantically match the Category filter's (selectedPolicyCategories?.length > 0): show the filter only when the relevant entities actually exist.

    What alternative solutions did you explore? (Optional)

    Alternatives considered
    • Simply use selectedPolicyTagLists.length > 0 — closer mirror to the Category line, but a policy can have a tag-list container with zero tags inside it, so .length > 0 could still be true with no actual tags. Checking the nested tags content (as above) is more correct.
    • Drop the singlePolicyCondition and rely only on hasTags — would fix this report, but loses the intended "show the filter for the specific selected workspace" broadening that the Category filter also relies on.

    Confidence: High — the bug is a pure logic error confirmed in code: getAllPolicyValues never returns a falsy value, so !!selectedPolicyTagLists can never be false. No production logs needed.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/blob/1765e75a02a6990312f107ea45f848998ed1178f/src/hooks/useAdvancedSearchFilters.ts#L341) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.

  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jun 15, 2026
  6. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jun 15, 2026
  7. mukhrr commented on Jun 15, 2026

    @mukhrr
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2026-06-15 09:54:27 UTC.

    Proposal

    What is the root cause of that problem?

    The Tag filter visibility logic checks the wrong thing after tags are deleted.

    When tags are deleted, deletePolicyTags() does not immediately remove them from Onyx. It first marks each deleted tag with pendingAction: DELETE and enabled: false in optimistic data:

    const policyTagsOptimisticData: Record<string, Record<string, Partial<OnyxValueWithOfflineFeedback<PolicyTag>>>> = {
    [policyTag.name]: {
    tags: {
    ...tagsToDelete.reduce<Record<string, Partial<OnyxValueWithOfflineFeedback<PolicyTag>>>>((acc, tagName) => {
    acc[tagName] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, enabled: false};
    return acc;
    }, {}),
    },
    },
    };
    const onyxData: OnyxData<typeof ONYXKEYS.COLLECTION.POLICY_TAGS> = {
    optimisticData: [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
    value: policyTagsOptimisticData,

    Other tag UIs already treat those tags as unavailable. For example, workspace tag selection filters out tags with pendingAction: DELETE:

    const filterFunction = useCallback((tag: PolicyTag | undefined) => !!tag && tag.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, []);

    And the workspace tags page uses the same idea when deciding whether there are visible tags:

    const hasVisibleTags = tagList.some((tag) => tag.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || isOffline);

    The advanced search Category filter already follows this pattern: it only considers categories whose pendingAction is not DELETE:

    const availablePolicyCategoriesSelector = (policyCategories: OnyxCollection<PolicyCategories>) =>
    Object.fromEntries(
    Object.entries(policyCategories ?? {}).filter(([, categories]) =>
    Object.values(categories ?? {}).some((category) => category.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE),
    ),
    );

    But the Tag filter does not. hasTagsSelector() only checks whether tagList.tags has keys, so tags pending deletion still count as available:

    const hasTagsSelector = (allPolicyTagLists: OnyxCollection<PolicyTagLists>) => {
    for (const policyTagList of Object.values(allPolicyTagLists ?? {})) {
    if (!policyTagList) {
    continue;
    }
    for (const tagList of Object.values(policyTagList)) {
    if (Object.keys(tagList.tags ?? {}).length > 0) {
    return true;
    }
    }
    }
    return false;
    };

    Then the selected-policy condition also only checks whether selectedPolicyTagLists exists:

    const [allPolicyTagLists = getEmptyObject<NonNullable<OnyxCollection<PolicyTagLists>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
    const selectedPolicyTagLists = getAllPolicyValues(policyID, ONYXKEYS.COLLECTION.POLICY_TAGS, allPolicyTagLists);
    const [hasTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: hasTagsSelector});
    const {workspaces} = useAdvancedSearchFiltersWorkspaces(policies);
    // When looking if a user has any categories to display, we want to ignore the policies that are of type PERSONAL
    const hasNonPersonalPolicyCategories = Object.keys(allPolicyCategories).some((policyCategoryId) => {
    const categoryPolicyID = policyCategoryId.replace(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, '');
    const policy = policies[`${ONYXKEYS.COLLECTION.POLICY}${categoryPolicyID}`];
    return !!policy && policy.type !== CONST.POLICY.TYPE.PERSONAL;
    });
    const shouldDisplayCategoryFilter = shouldDisplayFilter(hasNonPersonalPolicyCategories ? 1 : 0, policyDerived?.areCategoriesEnabled ?? false, selectedPolicyCategories?.length > 0);
    const shouldDisplayTagFilter = shouldDisplayFilter(hasTags ? 1 : 0, policyDerived?.areTagsEnabled ?? false, !!selectedPolicyTagLists);

    That means a workspace with an empty or pending-delete tag container can still make the Tag filter visible.

    History supports this RCA: PR #84679 / commit f62d5a2 fixed the same selected-workspace empty-data problem inside the Tag and Category filter pages by avoiding fallback to all workspaces when a selected workspace had no values:

    f62d5a2

    This issue is the same availability bug one level earlier: the filter row itself is still shown because the hook counts deleted/empty tag data as available.

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

    Make Tag availability use the same “available value” definition as Category and the workspace tag pages: a tag should count only if it is not pending deletion.

    Also make the selected-policy case depend on the selected policies’ available tags, instead of the existence of a policyTags_<policyID> object.

    Small diff excerpt:

    +function hasAvailableTags(policyTagLists: PolicyTagLists | undefined): boolean {
    +    return Object.values(policyTagLists ?? {}).some((tagList) =>
    +        Object.values(tagList.tags ?? {}).some((tag) => tag.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE),
    +    );
    +}
    
     const hasTagsSelector = (allPolicyTagLists: OnyxCollection<PolicyTagLists>) => {
         for (const policyTagList of Object.values(allPolicyTagLists ?? {})) {
    -        if (!policyTagList) {
    -            continue;
    -        }
    -        for (const tagList of Object.values(policyTagList)) {
    -            if (Object.keys(tagList.tags ?? {}).length > 0) {
    -                return true;
    -            }
    +        if (hasAvailableTags(policyTagList)) {
    +            return true;
             }
         }
         return false;
     };

    Then use selected-policy availability when a workspace filter is active:

     const selectedPolicyTagLists = getAllPolicyValues(policyID, ONYXKEYS.COLLECTION.POLICY_TAGS, allPolicyTagLists);
     const [hasTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: hasTagsSelector});
    +const hasSelectedPolicyTags = selectedPolicyTagLists.some(hasAvailableTags);
    +const shouldCheckSelectedPolicies = !!policyID?.length;
    
    -const shouldDisplayTagFilter = shouldDisplayFilter(hasTags ? 1 : 0, policyDerived?.areTagsEnabled ?? false, !!selectedPolicyTagLists);
    +const shouldDisplayTagFilter = shouldDisplayFilter(
    +    shouldCheckSelectedPolicies ? (hasSelectedPolicyTags ? 1 : 0) : (hasTags ? 1 : 0),
    +    policyDerived?.areTagsEnabled ?? false,
    +);

    This avoids regression because:

    • No workspace selected: behavior still depends on whether any workspace has available tags.
    • Workspace selected: Tag only appears if at least one selected workspace has available tags.
    • Tags enabled but all tags deleted: Tag is hidden, matching Category behavior.
    • Tags pending deletion: Tag is hidden immediately, matching existing workspace tag UI.
    • The existing areTagsEnabled feature flag still gates the filter, so disabled Tags workspaces stay unchanged.

    We should also add a focused test around useAdvancedSearchFilters or its extracted availability helpers for these cases: no tags, pending-delete tags, selected workspace with tags, selected workspace without tags while another workspace has tags.

    What alternative solutions did you explore? (Optional)

    We could hide deleted tags only inside SearchFiltersTagPage, but that would still leave a Tag row that opens a mostly empty picker. The root problem is the filter visibility decision in useAdvancedSearchFilters, so fixing the availability check there is the smaller and safer fix.

  8. KJ21-ENG commented on Jun 15, 2026

    @KJ21-ENG
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2026-06-15 09:59:23 UTC.

    Proposal

    What is the root cause of that problem?

    The advanced filter list is built by useAdvancedSearchFilters(). Category is hidden correctly because its visibility check only passes the selected-policy override when selected policies actually have category data.

    Tag uses a different override:

    const selectedPolicyCategories = getAllPolicyValues(policyID, ONYXKEYS.COLLECTION.POLICY_CATEGORIES, allPolicyCategories);
    const [allPolicyTagLists = getEmptyObject<NonNullable<OnyxCollection<PolicyTagLists>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
    const selectedPolicyTagLists = getAllPolicyValues(policyID, ONYXKEYS.COLLECTION.POLICY_TAGS, allPolicyTagLists);
    const [hasTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: hasTagsSelector});
    const {workspaces} = useAdvancedSearchFiltersWorkspaces(policies);
    // When looking if a user has any categories to display, we want to ignore the policies that are of type PERSONAL
    const hasNonPersonalPolicyCategories = Object.keys(allPolicyCategories).some((policyCategoryId) => {
    const categoryPolicyID = policyCategoryId.replace(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, '');
    const policy = policies[`${ONYXKEYS.COLLECTION.POLICY}${categoryPolicyID}`];
    return !!policy && policy.type !== CONST.POLICY.TYPE.PERSONAL;
    });
    const shouldDisplayCategoryFilter = shouldDisplayFilter(hasNonPersonalPolicyCategories ? 1 : 0, policyDerived?.areCategoriesEnabled ?? false, selectedPolicyCategories?.length > 0);
    const shouldDisplayTagFilter = shouldDisplayFilter(hasTags ? 1 : 0, policyDerived?.areTagsEnabled ?? false, !!selectedPolicyTagLists);

    selectedPolicyTagLists comes from getAllPolicyValues(), which always returns an array:

    function getAllPolicyValues<T extends OnyxCollectionKey>(
    policyID: string[] | undefined,
    key: T,
    policyData: OnyxCollection<OnyxCollectionValuesMapping[T]>,
    ): Array<OnyxCollectionValuesMapping[T]> {
    if (!policyData || !policyID) {
    return [];
    }
    return policyID.map((id) => policyData?.[`${key}${id}`]).filter((data) => !!data) as Array<OnyxCollectionValuesMapping[T]>;

    So !!selectedPolicyTagLists is true even when no workspace filter is selected, and it is also true when a selected workspace only has an empty tag-list object with no tag values. When Tags are enabled, that truthy override keeps the Tag filter visible. The Tag page then adds the built-in No tag option before adding real tag names, so the user sees a Tag filter with only No tag.

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

    Update src/hooks/useAdvancedSearchFilters.ts so the Tag filter override checks for actual tag entries instead of checking whether the returned array object exists.

    We can reuse the existing PolicyUtils.hasTags() helper or extract the traversal already used by hasTagsSelector, then derive something like hasSelectedPolicyTags = selectedPolicyTagLists.some(hasPolicyTags). Use that value in shouldDisplayTagFilter instead of !!selectedPolicyTagLists.

    This keeps the change scoped to client-side filter visibility. It should not change the Tag picker's No tag option, the existing -has:tag query serialization, or backend/API behavior.

    Please update tests/unit/hooks/useAdvancedSearchFilters.test.ts so the current empty-tag-list case expects Tag to be hidden. Also cover:

    • Tags enabled with no selected workspace and no real tags: Tag hidden.
    • Tags enabled with a selected workspace whose tag list has no tag values: Tag hidden.
    • Tags enabled with at least one real tag value: Tag visible.
    • Existing Category visibility behavior remains unchanged.

    What alternative solutions did you explore? (Optional)

    I considered removing No tag from the Tag picker when there are no real tags, but that would only hide the symptom after the bad filter row is already visible. The correct fix is to prevent the Tag filter row from being shown when there are no real tag values to filter by.

  9. melvin-bot commented on Jun 15, 2026

    @melvin-bot

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

  10. ahmdshrif commented on Jun 15, 2026

    @ahmdshrif
    Contributor

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  11. changed the title [-]Spend - Tag filter is present when account has no tag[/-] [+][$250] Spend - Tag filter is present when account has no tag[/+] on Jun 15, 2026
  12. melvin-bot commented on Jun 15, 2026

    @melvin-bot
  13. 64 remaining items

  14. melvin-bot commented on Jun 28, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  15. melvin-bot commented on Jun 28, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@mallenexpensify)

    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/2066458272251739905/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  16. DylanDylann commented on Jul 1, 2026

    @DylanDylann
    Contributor

    @mallenexpensify Please reassign this issue to @daledah

  17. melvin-bot commented on Jul 1, 2026

    @melvin-bot

    @mallenexpensify Whoops! This issue is 2 days overdue. Let's get this updated quick!

  18. mallenexpensify commented on Jul 2, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @daledah due $250 via NewDot

  19. quinthar commented on Aug 19, 2026

    @quinthar
    Contributor

    Approved $250 to @daledah

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

Metadata

Metadata

Labels

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

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions