You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2025-12-25] [$250] Distance rate - Error shows up after adding and deleting distance rate offline #76027
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
Therefore, when we call delete policy distance rates, it returns error "Invalid ID in custom unit rate"
What changes do you think we should make in order to solve the problem?
We should reset success deleted rate from Onyx as well
successRates[rateID]=null;
What alternative solutions did you explore? (Optional)
NA
Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.
Please re-state the problem that we are trying to solve in this issue.
When a user deletes distance rates while offline and then goes back online, the deleted rates reappear. When attempting to delete these rates again, an error occurs. The expected behavior is that the rates should be deleted successfully without errors.
What is the root cause of that problem?
The issue occurs in the deletePolicyDistanceRates function in App/src/libs/actions/Policy/DistanceRate.ts. When a distance rate is successfully deleted, the function does not properly remove it from the Onyx store.
Root Cause Analysis:
Missing deletion in success data: The successData in deletePolicyDistanceRates only includes rates that are NOT being deleted. For deleted rates, the function sets pendingAction: DELETE in the optimistic update, but the success data doesn't set these rates to null to remove them from the store.
Server sync conflict: When the user goes offline, deletes a rate, and then comes back online:
The optimistic update marks the rate with pendingAction: DELETE
The API call is queued
When online, the server sync may bring back the rate (if the deletion hasn't completed yet)
The success handler doesn't remove the rate from the store, so it persists even after successful deletion
Comparison with similar code: The deletePolicyTaxes function in App/src/libs/actions/TaxRate.ts correctly handles this by setting deleted taxes to null in the success data (line 377), which removes them from the Onyx store.
Code Location:
App/src/libs/actions/Policy/DistanceRate.ts - deletePolicyDistanceRates function (lines 393-507)
What changes do you think we should make in order to solve the problem?
Change 1: Update successRates type to allow null values
In App/src/libs/actions/Policy/DistanceRate.ts, update the type of successRates to allow null values:
constsuccessRates: Record<string,Rate|null>={};
Why: This allows us to set deleted rates to null in the success data, which removes them from the Onyx store.
Change 2: Set deleted rates to null in success data
In the same function, when building successRates, set deleted rates to null:
for(constrateIDofObject.keys(currentRates)){if(rateIDsToDelete.includes(rateID)){optimisticRates[rateID]={
...currentRates[rateID],enabled: false,pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,};// Set deleted rates to null in success data to remove them from the storesuccessRates[rateID]=null;failureRates[rateID]={
...currentRates[rateID],pendingAction: null,errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),};}else{optimisticRates[rateID]=currentRates[rateID];successRates[rateID]={
...currentRates[rateID],pendingAction: null,};}}
What alternative solutions did you explore? (Optional)
changed the title [-]Distance rate - Error shows up after adding and deleting distance rate offline[/-][+][$250] Distance rate - Error shows up after adding and deleting distance rate offline[/+]on Dec 3, 2025
Issue is ready for payment but no BZ is assigned. @lydiabarclay you are the lucky winner! Please verify the payment summary looks correct and complete the checklist. Thanks!
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion:
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
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
Activity
melvin-bot commentedon Nov 25, 2025
Triggered auto assignment to @muttmuure (
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.thelullabyy commentedon Nov 25, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
The second rate reappears after returning online.
When trying to delete the second rate again, error shows up.
What is the root cause of that problem?
When deleting a rate that was created offline with
pendingAction: 'add', the successData doesn't include the deleted rate IDsAlso deleted rates aren't included in successRates as well
App/src/libs/actions/Policy/DistanceRate.ts
Lines 407 to 416 in 6abc35a
Therefore, when we call delete policy distance rates, it returns error "Invalid ID in custom unit rate"
What changes do you think we should make in order to solve the problem?
We should reset success deleted rate from Onyx as well
What alternative solutions did you explore? (Optional)
NA
Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.
abbasifaizan70 commentedon Nov 25, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user deletes distance rates while offline and then goes back online, the deleted rates reappear. When attempting to delete these rates again, an error occurs. The expected behavior is that the rates should be deleted successfully without errors.
What is the root cause of that problem?
The issue occurs in the
deletePolicyDistanceRatesfunction inApp/src/libs/actions/Policy/DistanceRate.ts. When a distance rate is successfully deleted, the function does not properly remove it from the Onyx store.Root Cause Analysis:
Missing deletion in success data: The
successDataindeletePolicyDistanceRatesonly includes rates that are NOT being deleted. For deleted rates, the function setspendingAction: DELETEin the optimistic update, but the success data doesn't set these rates tonullto remove them from the store.Server sync conflict: When the user goes offline, deletes a rate, and then comes back online:
pendingAction: DELETEComparison with similar code: The
deletePolicyTaxesfunction inApp/src/libs/actions/TaxRate.tscorrectly handles this by setting deleted taxes tonullin the success data (line 377), which removes them from the Onyx store.Code Location:
App/src/libs/actions/Policy/DistanceRate.ts-deletePolicyDistanceRatesfunction (lines 393-507)What changes do you think we should make in order to solve the problem?
Change 1: Update
successRatestype to allow null valuesIn
App/src/libs/actions/Policy/DistanceRate.ts, update the type ofsuccessRatesto allownullvalues:Why: This allows us to set deleted rates to
nullin the success data, which removes them from the Onyx store.Change 2: Set deleted rates to null in success data
In the same function, when building
successRates, set deleted rates tonull:What alternative solutions did you explore? (Optional)
N/A
bernhardoj commentedon Nov 26, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
The deleted distance rate re-appears after going online.
What is the root cause of that problem?
Whenever we delete a rate, we optimistically set the pending action to delete, but also merge all the current rates when success.
App/src/libs/actions/Policy/DistanceRate.ts
Lines 400 to 424 in 29e1abf
So, when we delete the 3rd rate, the 2nd rate will be included on the success data.
What changes do you think we should make in order to solve the problem?
We don't need to include the current rates on the success data (and optimisticRates and failureRates) because we use MERGE.
melvin-bot commentedon Nov 29, 2025
@muttmuure Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
melvin-bot commentedon Dec 1, 2025
@muttmuure Huh... This is 4 days overdue. Who can take care of this?
melvin-bot commentedon Dec 3, 2025
@muttmuure Still overdue 6 days?! Let's take care of this!
[-]Distance rate - Error shows up after adding and deleting distance rate offline[/-][+][$250] Distance rate - Error shows up after adding and deleting distance rate offline[/+]melvin-bot commentedon Dec 3, 2025
Job added to Upwork: https://www.upwork.com/jobs/~021996317916684459409
30 remaining items
melvin-bot commentedon Dec 25, 2025
Issue is ready for payment but no BZ is assigned. @lydiabarclay you are the lucky winner! Please verify the payment summary looks correct and complete the checklist. Thanks!
mollfpr commentedon Dec 29, 2025
Waiting for payment! cc @lydiabarclay
@DylanDylann do we need the BZ checklist here?
DylanDylann commentedon Dec 29, 2025
BugZero Checklist:
[Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment: Fix: Distance Rate added offline seen grayed out going online then back offline #53725 (comment)
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion:
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue: https://github.com/Expensify/Expensify/issues/584455
Regression Test Proposal
Test:
Precondition: have a workspace with a distance rate enabled
Do we agree 👍 or 👎
Zapier Logs
Run ID: 00040eee-c6e5-a10a-b21a-c8b7ba353644melvin-bot commentedon Jan 1, 2026
@mollfpr Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
mollfpr commentedon Jan 5, 2026
Waiting for payment.
lydiabarclay commentedon Jan 6, 2026
Payment Summary
Contributor: @bernhardoj due $250 via NewDot
Contributor+: @DylanDylann due $250 via NewDot
✅ Regression test filed
bernhardoj commentedon Jan 6, 2026
Requested in ND.
garrettmknight commentedon Jan 14, 2026
$250 approved for @bernhardoj
JmillsExpensify commentedon Jan 20, 2026
$250 approved for @DylanDylann