Skip to content

[Due for payment 2026-04-14] [Due for payment 2026-03-13] [$250] Distance - Old unit persists when creating distance expense after changing distance unit #84010

Closed

Description

@nlemma

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.3.28-1
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #74967
Email or phone of affected tester (no customers): isodjnosidjiojiojiso@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Money Requests

Action Performed:

Precondition:

  • Enable distance rates.
  • Change distance unit to Kilometers.
  1. Go to staging.new.expensify.com
  2. Go to self DM.
  3. Click + > Track distance > Manual.
  4. Enter amount > Next.
  5. Click Create expense.
  6. Open the expense.
  7. Click Distance field.

Expected Result:

In Step 3 and 4, when creating distance expense, distance unit should default to kilometer (from the changes in precondition).

Actual Result:

In Step 3 and 4, when creating distance expense, old distance unit (mile) persists.
In Step 6, after creating the expense, the distance amount persists but with the different unit (kilometer).
In Step 7, distance editor still shows miles when the menu item shows kilometers.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7092490_1772511385574.023.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @dylanexpensify
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022028768106167481138
  • Upwork Job ID: 2028768106167481138
  • Last Price Increase: 2026-03-03
  • Automatic offers:
    • FitseTLT | Reviewer | 110642893

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 3, 2026
  2. melvin-bot commented on Mar 3, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #74967

  3. melvin-bot commented on Mar 3, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. melvin-bot commented on Mar 3, 2026

    @melvin-bot

    Triggered auto assignment to @CortneyOfstad (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.

  5. github-actions commented on Mar 3, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  6. OSBotify commented on Mar 3, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #74967 - "Fix - [Unreported] Add distance rate to the distance expenses tracked in selfDM" by @FitseTLT (High confidence)
    Related Issues: None

    Recommendation: REVERT

    PR #74967 adds functionality for distance rates in self DM (unreported expenses), but introduces a bug where the distance unit from policy settings is not properly applied during distance expense creation. The old unit persists during creation, then switches to the new unit after the expense is created, causing confusion and incorrect data display.

    Labels: No label changes needed. DeployBlockerCash is correctly applied (this is a frontend/App bug that blocks the App deploy).

    Detailed Analysis

    Evidence

    The issue states that when creating a distance expense after changing the distance unit from miles to kilometers:

    1. During creation (steps 3-4), the old unit (miles) persists
    2. After creating the expense (step 6), the distance amount persists but with the different unit (kilometers)
    3. The distance editor still shows miles when the menu item shows kilometers

    This matches the changes introduced in PR #74967, which modified how distance rates are handled for track expenses in self DM. The PR was merged on 2026-02-28 and is included in the 9.3.28-1 staging deploy checklist.

    Verification

    PR #74967 modified the following distance-related files:

    • src/libs/DistanceRequestUtils.ts - Added isTrackDistanceExpense parameter to rate selection logic
    • src/pages/iou/request/DistanceRequestStartPage.tsx - Changed to use usePolicyForTransaction hook
    • src/components/MoneyRequestConfirmationList.tsx - Added policyForMovingExpenses to rate calculation
    • Multiple distance request step files removed customUnitRateID parameter

    The bug appears to be in how the distance unit is initialized during the creation flow. The setMoneyRequestDistanceRate function (lines 1798-1821 in src/libs/actions/IOU/index.ts) properly updates the distance unit when a rate is selected, but during initial creation on the confirmation page, the unit may not be properly initialized from the policy rate settings for track expenses.

    Root Cause

    When creating a distance expense in self DM after changing the distance unit setting, the transaction is initialized without the updated distance unit from the policy settings. The unit gets updated only after a rate is explicitly selected or after the expense is created, causing the unit mismatch during the creation flow.

  7. MelvinBot commented on Mar 3, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When a user enables distance rates, changes the distance unit to kilometers in their workspace settings, and then creates a TRACK distance expense from self-DM using the manual distance flow, the distance input UI still shows miles as the unit. After creating the expense, the unit inconsistently shows kilometers in some views and miles in the distance editor.

    What is the root cause of that problem?

    The root cause is in IOURequestStepDistanceManual.tsx (lines 106-116). When determining the distance unit to display, the component calls:

    const shouldUseDefaultExpensePolicy = shouldUseDefaultExpensePolicyUtil(iouType, defaultExpensePolicy);
    
    const mileageRate = DistanceRequestUtils.getRate({
        transaction,
        policy: shouldUseDefaultExpensePolicy ? defaultExpensePolicy : policy,
        useTransactionDistanceUnit: false,
    });
    const unit = mileageRate.unit;

    The function shouldUseDefaultExpensePolicy (src/libs/shouldUseDefaultExpensePolicy.ts:7-14) only returns true when iouType === CONST.IOU.TYPE.CREATE:

    function shouldUseDefaultExpensePolicy(iouType, defaultExpensePolicy) {
        return (
            iouType === CONST.IOU.TYPE.CREATE &&
            isPaidGroupPolicy(defaultExpensePolicy) &&
            defaultExpensePolicy?.isPolicyExpenseChatEnabled &&
            !shouldRestrictUserBillableActions(defaultExpensePolicy.id)
        );
    }

    When creating from self-DM's "+" button via "Track distance > Manual", the iouType is CONST.IOU.TYPE.TRACK (set in AttachmentPickerWithMenuItems.tsx:270). Since TRACK !== CREATE, shouldUseDefaultExpensePolicy returns false, and the component falls back to policy from usePolicy(report?.policyID), which is null for self-DM reports (they have no policyID).

    With a null policy, DistanceRequestUtils.getRate() takes the following path:

    1. getMileageRates(null) returns {} (empty)
    2. The transaction draft has customUnitRateID = FAKE_P2P_ID (set by getCustomUnitRateID at DistanceRequestUtils.ts:333 which returns FAKE_P2P_ID when policy is empty)
    3. isCustomUnitRateIDForP2P(transaction) returns true at DistanceRequestUtils.ts:414
    4. getRateForP2P(currency, transaction) is called, which returns the hardcoded P2P rate from CONST.CURRENCY_TO_DEFAULT_MILEAGE_RATE — for USD, this is {rate: 72.5, unit: "mi"} (CONST/index.ts:6887-6890)

    So regardless of the workspace's distance unit configuration, the creation UI always shows the P2P default unit for the currency (miles for USD).

    The same issue affects IOURequestStepDistanceOdometer which uses a similar pattern. The IOURequestStepDistanceMap component also has this issue since it doesn't pass unit to handleMoneyRequestStepDistanceNavigation (see IOURequestStepDistanceMap.tsx:301-334), so the self-DM P2P unit conversion is never performed for map-based requests.

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

    The fix should ensure the workspace's distance unit is used for TRACK distance expenses from self-DM:

    1. In IOURequestStepDistanceManual.tsx (line 113): When shouldUseDefaultExpensePolicy is false but the report is a self-DM (and the user has a defaultExpensePolicy), fall back to defaultExpensePolicy instead of the null policy. Something like:

      policy: shouldUseDefaultExpensePolicy ? defaultExpensePolicy : (policy ?? defaultExpensePolicy)
      

      This ensures that when the direct report policy is null (self-DM), the user's default workspace policy is used to determine the distance unit.

    2. Apply the same fix in IOURequestStepDistanceOdometer.tsx which has the same pattern.

    3. Consider the same approach in IOURequestStepDistanceMap.tsx and in handleMoneyRequestStepDistanceNavigation where the unit parameter is used for self-DM P2P conversion.

    What alternative solutions did you explore? (Optional)

    An alternative would be to modify shouldUseDefaultExpensePolicy to also return true for TRACK type, but that could have broader side effects since shouldUseDefaultExpensePolicy controls policy selection in many parts of the flow (participants, confirmation page, etc.). The more targeted fix of falling back to defaultExpensePolicy when policy is null is safer and more localized.

    Another alternative would be to set the correct customUnitRateID from the workspace policy during initMoneyRequest even for TRACK expenses in self-DM. However, this is architecturally complex because initMoneyRequest would need awareness of the default expense policy, and the transaction should use P2P rates in self-DM — the issue is only about the display unit during creation.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  8. 25 remaining items

  9. changed the title [-][$250] Distance - Old unit persists when creating distance expense after changing distance unit[/-] [+][Due for payment 2026-03-13] [$250] Distance - Old unit persists when creating distance expense after changing distance unit[/+] on Mar 6, 2026
  10. melvin-bot commented on Mar 6, 2026

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  11. melvin-bot commented on Mar 6, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.31-12 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-03-13. 🎊

    For reference, here are some details about the assignees on this issue:

  12. melvin-bot commented on Mar 6, 2026

    @melvin-bot

    @parasharrajat / @FitseTLT @dylanexpensify The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  13. melvin-bot commented on Mar 6, 2026

    @melvin-bot

    Current assignee @dylanexpensify is eligible for the Awaiting Payment assigner, not assigning anyone new.

  14. melvin-bot commented on Apr 7, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  15. jponikarchuk commented on Apr 7, 2026

    @jponikarchuk

    Deploy Blocker #87207 was identified to be related to the PR #84136 that attempted to fix this issue.

  16. changed the title [-][Due for payment 2026-03-13] [$250] Distance - Old unit persists when creating distance expense after changing distance unit[/-] [+][Due for payment 2026-04-14] [Due for payment 2026-03-13] [$250] Distance - Old unit persists when creating distance expense after changing distance unit[/+] on Apr 7, 2026
  17. melvin-bot commented on Apr 7, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.53-7 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-04-14. 🎊

    For reference, here are some details about the assignees on this issue:

  18. melvin-bot commented on Apr 7, 2026

    @melvin-bot

    @parasharrajat / @FitseTLT The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

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.EngineeringExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions