Skip to content

[Due for payment 2026-03-13] [$250] Distance - Distance unit and rate change after editing distance #83953

Closed

Description

@vincdargento

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-0
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:

  • Workspace distance unit must be different from personal distance unit.
  1. Go to staging.new.expensify.com
  2. Go to self DM.
  3. Create a manual distance expense.
  4. Open the expense.
  5. Click Distance.
  6. Edit the distance and save it.

Expected Result:

Distance unit and rate will not change after editing distance.

Actual Result:

Distance unit and rate change to personal distance unit and rate after editing distance.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

bug.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @heyjennahay
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022028610785708105535
  • Upwork Job ID: 2028610785708105535
  • Last Price Increase: 2026-03-02
  • Automatic offers:
    • FitseTLT | Reviewer | 110642194

Activity

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

    @melvin-bot

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

  3. melvin-bot commented on Mar 2, 2026

    @melvin-bot

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

  4. melvin-bot commented on Mar 2, 2026

    @melvin-bot

    Triggered auto assignment to @heyjennahay (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 2, 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 2, 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: ROLL FORWARD

    PR #74967 added the feature to allow workspace distance rates for track expenses in self DM, but missed updating the edit distance flow to use the correct policy reference. The fix is straightforward - a one-line change to pass the correct policy parameter.

    Labels: No label changes made. Keeping DeployBlockerCash as this is a frontend bug that requires an App PR fix.

    📋 Detailed Analysis

    Evidence

    PR #74967 was merged on 2026-02-28 and added support for workspace distance rates on track expenses in self DM. The issue reproduction steps match this new feature:

    • Create a distance expense in self DM with workspace distance unit different from personal unit
    • Edit the distance
    • Distance unit and rate incorrectly change to personal unit/rate

    Verification

    The bug occurs in /home/runner/_work/App/App/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx:

    Line 76: Gets the policy from the report

    const policy = usePolicy(report?.policyID);

    Line 82: Gets the policy for moving expenses (for track expenses)

    const {policyForMovingExpenses} = usePolicyForMovingExpenses();

    Line 191: PROBLEM - Uses wrong policy for track expenses

    policy,  // Should use policyForMovingExpenses for track expenses

    For track expenses in self DM, report?.policyID is undefined or refers to the personal policy, not the workspace policy. PR #74967 added policyForMovingExpenses to handle this, but the edit flow at line 191 still uses policy instead.

    Root Cause

    When updateMoneyRequestDistance is called during edit:

    1. It passes policy (personal policy for self DM reports)
    2. This flows down to getUpdatedTransaction in /home/runner/_work/App/App/src/libs/TransactionUtils/index.ts
    3. At line 726, it calls DistanceRequestUtils.getRate({transaction: updatedTransaction, policy})
    4. Since the policy is personal policy, it returns the personal P2P rate instead of the workspace rate
    5. The transaction gets updated with wrong unit/rate

    The fix is to check if this is a track expense (iouType === CONST.IOU.TYPE.TRACK) and use policyForMovingExpenses instead of policy when calling updateMoneyRequestDistance.

    Proposed Fix

    In /home/runner/_work/App/App/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx at line 191:

    policy: iouType === CONST.IOU.TYPE.TRACK ? policyForMovingExpenses : policy,

    This same fix likely needs to be applied to other distance edit pages:

    • IOURequestStepDistanceMap.tsx
    • IOURequestStepDistanceOdometer.tsx
    • IOURequestStepDistance.tsx (if it has similar edit logic)
  7. MelvinBot commented on Mar 2, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When editing a distance expense tracked in selfDM, the distance unit and rate change to personal defaults (e.g., miles) instead of keeping the original workspace's unit and rate (e.g., km). This happens when the workspace distance unit differs from the personal distance unit.

    What is the root cause of that problem?

    The distance editing step pages (IOURequestStepDistanceManual.tsx and IOURequestStepDistance.tsx) resolve the policy via usePolicy(report?.policyID) (lines 76 and 91 respectively). For selfDM transaction thread reports, report?.policyID is undefined, so policy resolves to null.

    This null policy is then passed to DistanceRequestUtils.getRate() with useTransactionDistanceUnit: false (line 111-115 of IOURequestStepDistanceManual.tsx). Inside getRate():

    1. getMileageRates(null) returns {} (empty)
    2. getDefaultMileageRate(null) returns undefined
    3. getDistanceUnit(undefined, undefined) falls back to CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES

    So the unit defaults to miles and rate to undefined. When the user saves, setMoneyRequestDistance() overwrites the transaction's distanceUnit with 'mi', and updateMoneyRequestDistance() recalculates the amount using the wrong unit/rate.

    By contrast, IOURequestStepDistanceRate.tsx (the rate editing page) uses usePolicyForTransaction() at line 66, which correctly resolves to policyForMovingExpenses for selfDM expenses. This inconsistency was introduced by PR #74967, which updated the rate page to use usePolicyForTransaction but did not update the distance editing pages.

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

    1. In IOURequestStepDistanceManual.tsx and IOURequestStepDistance.tsx: Replace usePolicy(report?.policyID) with usePolicyForTransaction({transaction, reportPolicyID: report?.policyID, action, iouType, policyDraft}), matching what IOURequestStepDistanceRate.tsx already does. This ensures the correct workspace policy is resolved for selfDM track expenses.

    2. In usePolicyForTransaction.ts: The current logic at line 51 only returns policyForSelfDMExpense for unreported expenses (transaction.reportID === UNREPORTED_REPORT_ID) or creating track expenses (action === CREATE && iouType === TRACK). SelfDM expenses being edited may not meet either condition. The condition should also cover editing track expenses in selfDM (when action === EDIT and the expense is in selfDM).

    What alternative solutions did you explore? (Optional)

    An alternative would be to pass policyForMovingExpenses through the getUpdatedTransaction() call chain in TransactionUtils/index.ts (lines 726, 777, 863 all call getRate() without policyForMovingExpenses). However, fixing the policy resolution at the component level is a cleaner approach since it addresses the root cause — the wrong policy being passed into the entire save flow — rather than patching individual call sites.


    Confidence: High — the evidence chain is complete from policy resolution → rate lookup → unit fallback → wrong save data. The rate editing page (IOURequestStepDistanceRate.tsx) already demonstrates the correct pattern at line 66.

    Relevant Code:

    • src/pages/iou/request/step/IOURequestStepDistanceManual.tsx:76 — uses usePolicy(report?.policyID) (wrong for selfDM)
    • src/pages/iou/request/step/IOURequestStepDistance.tsx:91 — same issue
    • src/pages/iou/request/step/IOURequestStepDistanceRate.tsx:66 — uses usePolicyForTransaction (correct pattern)
    • src/hooks/usePolicyForTransaction.ts:47-51 — condition needs to cover selfDM edit case
    • src/libs/DistanceRequestUtils.ts:372-374 — getDistanceUnit fallback to miles when policy is null

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

  8. 29 remaining items

  9. cristipaval commented on Mar 4, 2026

    @cristipaval
    Contributor

    Closing this since it is a backend issue. I created a separate backend issue to fix this.

  10. IuliiaHerets commented on Mar 4, 2026

    @IuliiaHerets

    Chrome / v9.3.30-1
    Distance unit stays personal when create track distance expense in Self DM

    Screen.Recording.2026-03-04.at.12.37.20.mp4
  11. melvin-bot commented on Mar 4, 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.

  12. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Mar 6, 2026
  13. changed the title [-][$250] Distance - Distance unit and rate change after editing distance[/-] [+][Due for payment 2026-03-13] [$250] Distance - Distance unit and rate change after editing distance[/+] on Mar 6, 2026
  14. melvin-bot commented on Mar 6, 2026

    @melvin-bot

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

  15. 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:

  16. melvin-bot commented on Mar 6, 2026

    @melvin-bot

    @parasharrajat / @FitseTLT @heyjennahay 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]

  17. melvin-bot commented on Mar 6, 2026

    @melvin-bot

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

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.EngineeringInternalRequires API changes or must be handled by Expensify staffWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions