Skip to content

[Due for payment 2026-05-22] [$250] [Unreported] Distance - After editing distance, Distance rate changes to personal rate #87204

Closed

Description

@mitarachim

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.53-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: #84136
Email or phone of affected tester (no customers): sjoinjojsodidsjodjso@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:

  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 distance and save it.

Expected Result:

After editing distance, Distance rate will not change to personal default rate.

Actual Result:

After editing distance, Distance rate changes to personal default rate.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7123251_1775526119275.7.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022052420629411040865
  • Upwork Job ID: 2052420629411040865
  • Last Price Increase: 2026-05-07
  • Automatic offers:
    • FitseTLT | Reviewer | 111354935
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Apr 7, 2026
  2. melvin-bot commented on Apr 7, 2026

    @melvin-bot

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

  3. melvin-bot commented on Apr 7, 2026

    @melvin-bot

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

  4. github-actions commented on Apr 7, 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.
  5. OSBotify commented on Apr 7, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #84136 "Feat - Add distance rate to the distance expenses tracked in selfDM" by @FitseTLT (High confidence)

    Recommendation: REVERT

    PR #84136 introduced the bug. When track tax is enabled and the user edits the distance on a track expense, the distance rate resets to the personal default rate instead of preserving the previously-selected rate.

    Labels: DeployBlockerCash is kept (App PR caused this). DeployBlocker is being removed as this is a frontend bug requiring a fix in Expensify/App, not the backend.

    Evidence:

    Verification - Key files modified by PR #84136 related to the bug:

    1. src/libs/DistanceRequestUtils.ts - The getCustomUnitRateID function was changed so that when isTrackDistanceExpense is true, it skips the lastSelectedDistanceRates lookup entirely and always returns the policy default rate. When the user edits the distance amount, this overrides the previously-selected rate (e.g., the one with 5% tax) with the policy default.

    2. src/pages/iou/request/step/IOURequestStepDistanceManual.tsx - The PR removed customUnitRateID from the args passed to handleMoneyRequestStepDistanceNavigation, so the user-selected rate is no longer forwarded when navigating after editing the manual distance.

    Root Cause:

    In DistanceRequestUtils.getCustomUnitRateID, for isTrackDistanceExpense: true, the condition that preserves lastSelectedDistanceRate was gated out (!isTrackDistanceExpense &&). When the user edits the distance amount on a track expense that has a custom rate with 5% tax selected, handleMoneyRequestStepDistanceNavigation calls getCustomUnitRateID with isTrackDistanceExpense: true, bypassing the previously-selected rate and returning the policy default rate. This rate reset then also discards the tax association, causing the behavior seen in the video.

  6. removed
    DeployBlockerIndicates it should block deploying the API
    on Apr 7, 2026
  7. MelvinBot commented on Apr 7, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When track tax is enabled and a user edits the distance on a self-DM track expense that uses a workspace distance rate, the rate resets to the personal default rate.

    What is the root cause of that problem?

    The usePolicyForTransaction hook at src/hooks/usePolicyForTransaction.ts:48-51 only returns policyForMovingExpenses (the workspace policy that owns the selected rate) when action === CREATE && iouType === TRACK. During an edit (action === EDIT), it falls through to reportPolicy — which is the self-DM's personal policy since the transaction thread inherits policyID from the self-DM parent report.

    This wrong policy is then passed through updateMoneyRequestDistance → getUpdatedTransaction → DistanceRequestUtils.getRate(). Since the workspace rate's customUnitRateID doesn't exist in the personal policy's mileage rates, getRate() falls back to the personal policy's defaultMileageRate at src/libs/DistanceRequestUtils.ts:431-432. The recalculated amount, currency, and merchant are then written optimistically with the wrong rate.

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

    Update the condition in usePolicyForTransaction (line 51) to also use policyForMovingExpenses when editing a self-DM track expense — not just when creating one. The fix:

    // Current (broken for edits):
    const isCreatingTrackExpense = action === CONST.IOU.ACTION.CREATE && iouType === CONST.IOU.TYPE.TRACK;
    
    // Fixed:
    const isSelfDMTrackExpense = iouType === CONST.IOU.TYPE.TRACK;
    const isCreatingTrackExpense = action === CONST.IOU.ACTION.CREATE && isSelfDMTrackExpense;

    Then update line 51:

    const policy = isUnreportedExpense || isCreatingTrackExpense || (action === CONST.IOU.ACTION.EDIT && isSelfDMTrackExpense)
        ? policyForSelfDMExpense
        : (reportPolicy ?? policyDraft);

    This ensures policyForMovingExpenses is used during both creation and editing of self-DM track expenses, so getRate() can find the correct customUnitRateID in the workspace policy.

    Investigation details

    Data flow of the bug:

    1. User creates distance expense in self-DM, selecting a rate from workspace policy (e.g., 5% tax)
    2. Transaction is created with customUnitRateID from workspace policy
    3. User edits distance → IOURequestStepDistanceManual resolves policy via usePolicyForTransaction({reportPolicyID: report?.policyID, action, iouType, transaction}) at line 79
    4. Since action=EDIT, isCreatingTrackExpense is false → policy resolves to reportPolicy (self-DM policy)
    5. Wrong policy passed to updateMoneyRequestDistance at line 195-210
    6. getUpdatedTransaction calls DistanceRequestUtils.getRate({transaction, policy}) at line 866 with wrong policy
    7. Rate lookup fails → falls back to personal default rate
    8. Wrong amount/currency/merchant written optimistically

    Why it only manifests with track tax enabled: Tax-enabled expenses use workspace rates that differ from the personal default. Without tax, the personal default rate may coincidentally match, masking the bug.

    What alternative solutions did you explore? (Optional)

    An alternative would be to look up the correct policy directly from the transaction's customUnitRateID inside getUpdatedTransaction in TransactionUtils/index.ts. However, this would require passing all policies to a utility function. Fixing the hook at the source (usePolicyForTransaction) is cleaner since it already has access to policyForMovingExpenses.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  8. 47 remaining items

  9. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on May 21, 2026
  10. melvin-bot commented on May 21, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  11. mallenexpensify commented on May 22, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @FitseTLT paid $250 via Upwork.

    ^ Test case created. Thx

  12. FitseTLT commented on May 22, 2026

    @FitseTLT
    Contributor

    nope @mallenexpensify

    It would also be nice if melvin knew the ND payed contributors list and auto generates the note to help you 🤔

  13. FitseTLT commented on Jun 2, 2026

    @FitseTLT
    Contributor

    @mallenexpensify on the above

  14. mallenexpensify commented on Jun 2, 2026

    @mallenexpensify
    Contributor

    @FitseTLT paid, summary updated above. Thx.

    It would also be nice if melvin knew the ND payed contributors list and auto generates the note to help you 🤔

    We're actively working on an improvement that will help (then we'll likely need another too, based on how frequently I mess it up.)

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.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions