Skip to content

[$175] Tags - The "Tag no longer valid" violation is displayed after deleting the single tag #102931

Closed

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: v9.5.1-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: https://test-management.browserstack.com/projects/2219752/test-runs/76494298/folder/57600809/95492766/1815299195
Email or phone of affected tester (no customers): wimbukwa+1021026@applausemail.com
Issue reported by: Applause Internal Team
Bug source: Regression TC Execution
Device used: Samsung A34 / Android 16
App Component: Workspace Settings

Action Performed:

Precondition: Logged into the Expensify App. Create a workspace.

  1. Navigate to Workspace Settings > Tags and add "Tag Alpha".
  2. Navigate to the workspace chat and create a manual expense using "Tag Alpha".
  3. Return to Workspace Settings > Tags and delete "Tag Alpha".
  4. Navigate back to the workspace chat and locate the expense report preview.
  5. Verify that no "Tag no longer valid" violation is displayed in the preview or the report details.

Expected Result:

The "Tag no longer valid" violation should not be displayed after deleting the tag.

Actual Result:

The "Tag no longer valid" violation is displayed after deleting the tag.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

To be added by Applause Leads

View all open jobs on GitHub

Applause Internal Information
Exported by: Julia Ponikarchuk
Bug ID: 7276234

Upwork Automation - Do Not Edit

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 3, 2026
  2. changed the title [-]Tags - The "Tag no longer valid" violation is displayed after deleting the tag[/-] [+]Tags - The "Tag no longer valid" violation is displayed after deleting the single tag[/+] on Oct 3, 2026
  3. MelvinBot commented on Oct 3, 2026

    @MelvinBot
    Contributor

    Issue Analysis

    Root Cause: This looks like expected behavior. The test case's expected result is out of date. A product decision in June 2026 changed the rule so that deleting the last tag still flags expenses that use it. auto select some values of transaction after deletion one of last 2 elements (Expensify/App#86932) made that change. It removed the "no enabled tags" check in ViolationsUtils.ts:104-115.

    Recommended Fix: Don't change the code. Update BrowserStack test case 95492766 so its expected result says: "The 'Tag no longer valid' violation is shown, online and offline." Then close this issue. A product owner should confirm, because the deciding discussion isn't public.

    I reproduced the behavior on web (dev). After I deleted the only tag, the expense showed "Tag no longer valid":

    Expense details after deleting the only tag: Tag no longer valid shown

    Investigation details

    History of this rule

    1. Fix frontend tagOutOfPolicy violations when no tags are enabled (March 2026) hid the violation when a workspace had no enabled tags.
    2. [$250] Expense - 'Tag no longer valid' error not displayed then changed the backend to create the violation for a deleted tag. That conflicted with step 1.
    3. [$250] Expense - The 'Tag no longer valid' violation appears after deleting the only tag came from the same test case (95492766). It was escalated to product. In this review comment, lakchote relayed the product answer: if the last tag is deleted, an expense that still holds it should show tagOutOfPolicy.
    4. Commit d6cda4c9a64 in PR 86932 removed the gate and flipped the unit tests to match. The step 3 issue was closed as handled by that PR. The test case was never updated.

    Current code path when you delete the only tag

    Note: PR 86932's offline test step still says the violation "is not shown". That contradicts the code and the review discussion. It appears to be copied from the original expected result in the step 3 issue, which may be where the stale expectation comes from.


    Next Steps: A product owner should confirm the violation is intended. If so, update test case 95492766 and close this issue. Reply with @MelvinBot <your feedback> to refine this analysis.

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Oct 3, 2026
  5. melvin-bot commented on Oct 3, 2026

    @melvin-bot

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

  6. changed the title [-]Tags - The "Tag no longer valid" violation is displayed after deleting the single tag[/-] [+][$175] Tags - The "Tag no longer valid" violation is displayed after deleting the single tag[/+] on Oct 3, 2026
  7. melvin-bot commented on Oct 3, 2026

    @melvin-bot
  8. Pintu-Jha commented on Oct 3, 2026

    @Pintu-Jha

    Proposal

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

    Create a workspace, add a single tag, create an expense with that tag, then delete the tag. The report preview and expense details show Tag no longer valid. They should not, because there is no other tag left to choose.

    What is the root cause of that problem?

    Last-tag delete still leaves the old tag string on the expense ("Tag Alpha"). Auto-replace in pushTransactionAutoSelectionsOnyxData only runs when one enabled tag is left (2 → 1). For 1 → 0 it does nothing.

    deletePolicyTags then calls pushTransactionViolationsOnyxData. Single-level logic in getTagViolationsForSingleLevelTags (src/libs/Violations/ViolationsUtils.ts) adds tagOutOfPolicy whenever !isTagInPolicy. It no longer checks hasEnabledTagsInList, so an empty tag list still creates the violation.

    That is the optimistic path for this bug. The same helper already knows an empty list is not a “pick another tag” case: missingTag is still gated on hasEnabledTagsInList.

    There is a second leftover from that split:

    getIsViolationFixed for tagOutOfPolicy still returns true when no tags are enabled. Confirmation already treats this as fixed. Preview / details / LHN do not, because they read the Onyx violation that the write path just added.

    On the expense itself, shouldShowTagDisabledAlert in MoneyRequestView is the real empty-list UX (delete the stale tag). Showing Tag no longer valid next to that is a dead-end Fix: the picker has nothing valid to select.

    So this is not a missing delete handler. It is the write path adding a violation that the “is this fixed?” helper and the disabled-tag alert already treat as not actionable.

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

    Keep tagOutOfPolicy when other tags are still enabled. Stop adding (and drop leftover) tagOutOfPolicy when the list has zero enabled tags.

    1. src/libs/Violations/ViolationsUtils.ts — getTagViolationsForSingleLevelTags

    hasEnabledTagsInList is already computed. Use it on add and on remove:

    if (!hasTagOutOfPolicyViolation && updatedTransaction.tag && !isTagInPolicy && hasEnabledTagsInList) {
        newTransactionViolations.push({
            name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY,
            type: CONST.VIOLATION_TYPES.VIOLATION,
            data: {tagName: tagNameToShow},
            showInReview: true,
        });
    }
    
    if (hasTagOutOfPolicyViolation && (!updatedTransaction.tag || isTagInPolicy || !hasEnabledTagsInList)) {
        newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY});
    }

    2. Same file — getTagViolationForIndependentTags

    That loop already continues when a level has no enabled tags for someTagLevelsRequired. Do the same before pushing tagOutOfPolicy for a stale value on a fully empty level, so last-tag-on-a-level matches single-level.

    3. tests/unit/ViolationUtilsTest.ts

    Update the two cases that currently require tagOutOfPolicy when every tag is disabled (should add tagOutOfPolicy when transaction has a stale tag and no tags are enabled and the “keep existing” sibling). Empty list → no tagOutOfPolicy. Leave tests where another tag in the list is still enabled.

    No change needed in deletePolicyTags itself. It already recomputes through pushTransactionViolationsOnyxData; fixing the helper fixes the optimistic preview.

    Deleting one tag while others remain still shows Tag no longer valid, which is correct.

    What alternative solutions did you explore? (Optional)

  9. substeemguy commented on Oct 3, 2026

    @substeemguy

    Proposal

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

    When a workspace has a single tag and an expense is created using that tag, deleting the tag from Workspace Settings > Tags results in a persistent "Tag no longer valid" (tagOutOfPolicy) violation on the expense in the report preview, expense details, and LHN.

    Because that tag was the only tag in the workspace and zero enabled tags remain, the user cannot select any valid tag to resolve the violation. The expected behavior is that no "Tag no longer valid" violation should be displayed once zero enabled tags remain in the workspace.


    What is the root cause of that problem?

    1. Unconditional addition & retention of tagOutOfPolicy in getTagViolationsForSingleLevelTags:
      In src/libs/Violations/ViolationsUtils.ts (lines 104–115):

      // Add 'tagOutOfPolicy' if the tag is not in policy. Not gated on enabled tags remaining, so deleting the
      // last tag still flags a transaction that holds the deleted tag. Mirrors 'categoryOutOfPolicy'.
      if (!hasTagOutOfPolicyViolation && updatedTransaction.tag && !isTagInPolicy) {
          const tagName = policyTagList[policyTagListName]?.name;
          const tagNameToShow = isDefaultTagName(tagName) ? undefined : tagName;
          newTransactionViolations.push({name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY, type: CONST.VIOLATION_TYPES.VIOLATION, data: {tagName: tagNameToShow}, showInReview: true});
      }
      
      // Remove 'tagOutOfPolicy' violation if tag is empty or in policy
      if (hasTagOutOfPolicyViolation && (!updatedTransaction.tag || isTagInPolicy)) {
          newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY});
      }

      When the single tag is deleted, hasEnabledTagsInList is false. However, line 106 deliberately did not gate on hasEnabledTagsInList based on the old assumption of mirroring categoryOutOfPolicy. Furthermore, line 113 does not reject tagOutOfPolicy when !hasEnabledTagsInList.

    2. Direct contradiction with getIsViolationFixed:
      In src/libs/Violations/ViolationsUtils.ts (lines 344–357), getIsViolationFixed contains the definitive resolution check:

      [`${CONST.VIOLATIONS_PREFIX}${CONST.VIOLATIONS.TAG_OUT_OF_POLICY}`]: () => {
          if (!tag) {
              return true;
          }
          if (!policyTagLists) {
              return false;
          }
          const hasAnyEnabledTags = Object.values(policyTagLists).some((tagList) => hasEnabledTags(tagList.tags));
          if (!hasAnyEnabledTags) {
              return true;
          }
          const hasMatchingTag = Object.values(policyTagLists).some((tagList) => !!tagList.tags?.[tag]?.enabled);
          return hasMatchingTag;
      },

      When zero enabled tags remain across the policy (!hasAnyEnabledTags), getIsViolationFixed already returns true (treating tagOutOfPolicy as resolved). However, because the write path in getTagViolationsForSingleLevelTags persists the violation into Onyx unconditionally, the report preview, LHN, and RBR count continue to display the stale violation.

    3. Mismatch with MoneyRequestView's shouldShowTagDisabledAlert:
      In src/components/ReportActionItem/MoneyRequestView.tsx (lines 546 and 1221–1224):

      const shouldShowTagDisabledAlert = (!policy?.areTagsEnabled || !policyHasEnabledTags) && !!transactionTag;
      ...
      if (shouldShowTagDisabledAlert) {
          showTagDisabledAlert(index);
          return;
      }

      When zero enabled tags remain in the workspace, clicking the tag row already triggers showTagDisabledAlert to prompt the user to remove the stale tag (since the picker cannot be opened). Flagging tagOutOfPolicy next to this creates an unfixable dead-end for the user.


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

    1. Update src/libs/Violations/ViolationsUtils.ts

    In getTagViolationsForSingleLevelTags (lines 104–115):

    • Add hasEnabledTagsInList to the condition for adding tagOutOfPolicy.
    • Add !hasEnabledTagsInList to the condition for removing tagOutOfPolicy.
        // Add 'tagOutOfPolicy' if the tag is not in policy and there are enabled tags remaining in policy
        if (!hasTagOutOfPolicyViolation && updatedTransaction.tag && !isTagInPolicy && hasEnabledTagsInList) {
            const tagName = policyTagList[policyTagListName]?.name;
            const tagNameToShow = isDefaultTagName(tagName) ? undefined : tagName;
            newTransactionViolations.push({name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY, type: CONST.VIOLATION_TYPES.VIOLATION, data: {tagName: tagNameToShow}, showInReview: true});
        }
    
        // Remove 'tagOutOfPolicy' violation if tag is empty, in policy, or there are no enabled tags remaining
        if (hasTagOutOfPolicyViolation && (!updatedTransaction.tag || isTagInPolicy || !hasEnabledTagsInList)) {
            newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY});
        }

    2. Update tests/unit/ViolationUtilsTest.ts

    Update the unit tests at lines 2083–2141 that previously required tagOutOfPolicy when zero tags are enabled:

    1. should add tagOutOfPolicy when transaction has a stale tag and no tags are enabled: Update name to should not add tagOutOfPolicy when transaction has a stale tag and no tags are enabled and assert:
      expect(result.value).not.toContainEqual({...tagOutOfPolicyViolation, data: {tagName: 'Meals'}});
    2. should keep existing tagOutOfPolicy when transaction has a stale tag and no tags are enabled: Update name to should remove existing tagOutOfPolicy when transaction has a stale tag and no tags are enabled and assert:
      expect(result.value).not.toContainEqual(tagOutOfPolicyViolation);
      expect(result.value).toContainEqual(duplicatedTransactionViolation);
    3. Add a test verifying single-tag deletion (workspace with 1 tag, expense tagged with it, tag deleted resulting in empty tags list {}) confirms zero violations returned.

    Tests where other tags in the list remain enabled (e.g. line 2022 and getIsViolationFixed line 4621) remain unchanged and ensure tagOutOfPolicy continues to be added when other valid tags exist.


    What alternative solutions did you explore? (Optional)

    1. Clearing transaction.tag in pushTransactionAutoSelectionsOnyxData when transitioning from 1 → 0 tags:
      pushTransactionAutoSelectionsOnyxData is designed for auto-selecting an alternative valid option (2 → 1). Erasing the transaction tag string directly would cause client/backend divergence because the backend retains historical transaction tag strings. It also breaks MoneyRequestView's intended shouldShowTagDisabledAlert flow, which lets users see the previous tag and explicitly confirm removal.

    2. UI-only suppression (hasVisibleViolationsForUser / useViolations):
      Hiding it only in the UI leaves the raw tagOutOfPolicy violation in Onyx, causing issues for export validations, external reports, and raw violation counters. Fixing it in ViolationsUtils.ts ensures complete consistency across Onyx and the UI.

  10. melvin-bot commented on Oct 3, 2026

    @melvin-bot

    📣 @garvijunagadh! 📣
    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>
    
  11. substeemguy commented on Oct 4, 2026

    @substeemguy

    Contributor details
    Your Expensify account email: garvijunagadh@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~01ff3c252bcc7ad776

  12. melvin-bot commented on Oct 4, 2026

    @melvin-bot

    ⚠️ Invalid email. Please make sure to create an Expensify account with this email first here.

  13. substeemguy commented on Oct 4, 2026

    @substeemguy

    Contributor details
    Your Expensify account email: garvijunagadh@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~01ff3c252bcc7ad776

  14. melvin-bot commented on Oct 4, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  15. camesenin commented on Oct 4, 2026

    @camesenin
  16. camesenin commented on Oct 4, 2026

    @camesenin
  17. melvin-bot commented on Oct 4, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  18. bonnhatnguyen commented on Oct 5, 2026

    @bonnhatnguyen
    Proposal

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

    In a workspace with a single tag (e.g. "Tag Alpha"), after creating an expense with that tag and subsequently deleting "Tag Alpha" from Workspace Settings > Tags, the expense displays a persistent "Tag no longer valid" (tagOutOfPolicy) violation on the report preview and transaction view. Because 0 enabled tags remain in the workspace, tapping the Tag row blocks the user from opening the tag picker, leaving them trapped in an unresolvable violation state.


    What is the root cause of that problem?

    There is an architectural inconsistency between getIsViolationFixed and getTagViolationsForSingleLevelTags in src/libs/Violations/ViolationsUtils.ts:

    1. getIsViolationFixed already defines the expected specification:
      In src/libs/Violations/ViolationsUtils.ts:349-352:

      const hasAnyEnabledTags = Object.values(policyTagLists).some((tagList) => hasEnabledTags(tagList.tags));
      if (!hasAnyEnabledTags) {
          return true;
      }

      And verified by the unit test at tests/unit/ViolationUtilsTest.ts:4612:
      it('should return true when tag exists but no tags are enabled')
      When a policy has zero enabled tags remaining, getIsViolationFixed authoritatively returns true (meaning tagOutOfPolicy is satisfied and should not block the user).

    2. getTagViolationsForSingleLevelTags violates this contract:
      In src/libs/Violations/ViolationsUtils.ts:100-115:

      const isTagInPolicy = policyTags ? !!policyTags[updatedTransaction.tag ?? '']?.enabled : false;
      const hasEnabledTagsInList = hasEnabledTags(policyTags);
      let newTransactionViolations = [...transactionViolations];
      
      // Add 'tagOutOfPolicy' if the tag is not in policy. Not gated on enabled tags remaining, so deleting the
      // last tag still flags a transaction that holds the deleted tag. Mirrors 'categoryOutOfPolicy'.
      if (!hasTagOutOfPolicyViolation && updatedTransaction.tag && !isTagInPolicy) {
          ...
          newTransactionViolations.push({name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY, ...});
      }
      
      // Remove 'tagOutOfPolicy' violation if tag is empty or in policy
      if (hasTagOutOfPolicyViolation && (!updatedTransaction.tag || isTagInPolicy)) {
          newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY});
      }

      Notice that while hasEnabledTagsInList is computed at line 101, it was only applied to missingTag. For tagOutOfPolicy:

      • It unconditionally pushes tagOutOfPolicy when !isTagInPolicy, even when zero enabled tags exist in the policy (!hasEnabledTagsInList).
      • It fails to reject/clear tagOutOfPolicy when the last remaining tag is deleted or disabled (!hasEnabledTagsInList).
    3. In getTagViolationForIndependentTags (multi-level tags):
      Lines 213–228 push tagOutOfPolicy for a selected tag level without checking hasEnabledTags(tags) for that level, causing the same deadlock on multi-level tag setups when a whole tag list is emptied.


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

    1. Update getTagViolationsForSingleLevelTags in src/libs/Violations/ViolationsUtils.ts

    Gate the addition of tagOutOfPolicy on hasEnabledTagsInList, and clear existing tagOutOfPolicy violations when zero enabled tags remain in the list:

    // Add 'tagOutOfPolicy' if the tag is not in policy and there are still enabled tags in the policy
    if (!hasTagOutOfPolicyViolation && updatedTransaction.tag && !isTagInPolicy && hasEnabledTagsInList) {
        const tagName = policyTagList[policyTagListName]?.name;
        const tagNameToShow = isDefaultTagName(tagName) ? undefined : tagName;
        newTransactionViolations.push({name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY, type: CONST.VIOLATION_TYPES.VIOLATION, data: {tagName: tagNameToShow}, showInReview: true});
    }
    
    // Remove 'tagOutOfPolicy' violation if tag is empty, in policy, or if no enabled tags remain in the policy
    if (hasTagOutOfPolicyViolation && (!updatedTransaction.tag || isTagInPolicy || !hasEnabledTagsInList)) {
        newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY});
    }

    2. Update getTagViolationForIndependentTags in src/libs/Violations/ViolationsUtils.ts

    In multi-level independent tag evaluations (lines 206–228), ensure tagOutOfPolicy is only added if that tag level contains enabled tags:

    const tags = policyTagList[policyTagKeys[i]].tags;
    const listHasEnabledTags = hasEnabledTags(tags);
    const isTagInPolicy = !!tags[selectedTag]?.enabled;
    if (!isTagInPolicy && listHasEnabledTags) {
        newTransactionViolations.push({
            name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY,
            type: CONST.VIOLATION_TYPES.VIOLATION,
            showInReview: true,
            data: {
                tagName: policyTagKeys.at(i),
            },
        });
        hasInvalidTag = true;
        break;
    }

    3. Update & Add Unit Tests in tests/unit/ViolationUtilsTest.ts

    1. Update existing tests in describe('getTagViolationsForSingleLevelTags') to verify that when hasEnabledTags returns false, tagOutOfPolicy is not added and is cleanly removed if previously present.
    2. Add a new test case verifying that deleting the last active tag in a policy strips the tagOutOfPolicy violation from all existing transactions.

    What alternative solutions did you explore? (Optional)

    1. Auto-clearing transaction.tag = '' when deleting the last tag:
      Rejected. Deleting workspace policy tags must not mutate historical transaction strings stored in the backend database.
    2. Hiding the violation purely in UI (MoneyRequestView.tsx):
      Rejected. Suppressing the error only in presentation leaves stale violation objects in Onyx, corrupting violation counts, RBR badges, LHN error indicators, and export validation. Handling it in ViolationsUtils.ts keeps Onyx data, UI rendering, and getIsViolationFixed in complete 100% harmony.

    Contributor details
    Your Expensify account email: bonnhatnguyen0@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~0139ed4098bdc50182

  19. melvin-bot commented on Oct 5, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  20. linhvovan29546 commented on Oct 5, 2026

    @linhvovan29546
    Contributor

    @Expensify/product Could you please confirm whether this issue is expected? If so, please request Applause to update the test case.
    Thanks

  21. trjExpensify commented on Oct 5, 2026

    @trjExpensify
    Contributor

    It's expected:

    Image

    It was rectified in #86932

    CC: @m-natarajan

  22. m-natarajan commented on Oct 5, 2026

    @m-natarajan

    Thanks, Updated the test case @trjExpensify

  23. linhvovan29546 commented on Oct 6, 2026

    @linhvovan29546
    Contributor

    Close the issue because the test case has been updated.

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.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