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-08-29] [$250] Expense - Split distance expense shows unexpected error with rate not valid &duplicate violation #67213
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
changed the title [-]Expense - Split distance expense shows unexpected error with rate not valid &duplicate violation[/-][+][$250] Expense - Split distance expense shows unexpected error with rate not valid &duplicate violation[/+]on Aug 4, 2025
Please re-state the problem that we are trying to solve in this issue.
Split distance expense shows unexpected error with rate not valid &duplicate violation
What is the root cause of that problem?
When we delete the old rate, the rate of the first/second expense will be out of policy because it was removed.
Continuing to click ‘More’ and splitting the expense using a rate that has been removed or is out of policy will result in a backend validation error, preventing the split.
Due to invalid data, the split expense incorrectly appears after the API call fails
What changes do you think we should make in order to solve the problem?
To fix this issue, we should validate the distance rate before proceeding with the split. If the rate doesn’t exist or is disabled, we should display an error and return early.
const customUnitRateID = originalTransaction?.comment?.customUnit?.customUnitRateID;
if (customUnitRateID && policy) {
const customUnitRate = getDistanceRateCustomUnitRate(policy, customUnitRateID);
// If the rate doesn't exist or is disabled, show an error and return early
if (!customUnitRate || !customUnitRate.enabled) {
const errorMessage = !customUnitRate ? 'iou.error.invalidRate' : 'iou.error.genericEditFailureMessage';
console.log('****** errorMessage ******', errorMessage);
// Show error to user
Onyx.merge(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${originalTransactionID}`, {
errors: getMicroSecondOnyxErrorWithTranslationKey(errorMessage),
});
return;
}
}
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
none
What alternative solutions did you explore? (Optional)
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.
Option 1:
We will automatically select a valid rate when splitting an expense
function getValidDistanceRate(policy: OnyxEntry<OnyxTypes.Policy>, originalRateID?: string): string | undefined {
if (!policy?.customUnits) {
return undefined;
}
const distanceUnit = getDistanceRateCustomUnit(policy);
if (!distanceUnit?.rates) {
return undefined;
}
// Check if the original rate is still valid and enabled
if (originalRateID) {
const originalRate = getDistanceRateCustomUnitRate(policy, originalRateID);
if (originalRate?.enabled && originalRate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return originalRateID;
}
}
// Get the default rate (first rate created) if it's enabled
const defaultRate = DistanceRequestUtils.getDefaultMileageRate(policy);
if (defaultRate?.customUnitRateID && defaultRate.enabled) {
const rate = getDistanceRateCustomUnitRate(policy, defaultRate.customUnitRateID);
if (rate?.enabled && rate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return defaultRate.customUnitRateID;
}
}
// Find any enabled rate as fallback
const enabledRates = Object.entries(distanceUnit.rates).filter(([, rate]) => rate.enabled && rate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
if (enabledRates.length > 0) {
return enabledRates.at(0)?.[0]; // Return the first enabled rate ID
}
return undefined;
}
// If the original transaction is a distance request, ensure we use a valid rate
if (originalTransaction && isDistanceRequestTransactionUtils(originalTransaction)) {
const originalRateID = originalTransaction.comment?.customUnit?.customUnitRateID;
const validRateID = getValidDistanceRate(policy, originalRateID);
// If the original rate is invalid but we found a valid one, update the transaction params
if (validRateID && validRateID !== originalRateID) {
// Add customUnitRateID to transactionParams since it's a distance request
(transactionParams as RequestMoneyTransactionParams).customUnitRateID = validRateID;
}
}
Option 2:
The BE needs to be updated to not return a 402 when we split an expense with an invalid rate
@allroundexperts looks like both PRs have been merged, is that correct? For payment, did we increase the scope of this issue or does the $250 sound reasonable for the work done?
1a. Result of the original design (eg. a case wasn't considered)
1b. Mistake during implementation
1c. Backend bug
1z. Other:
Where bug was reported:
2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
2b. Reported on staging (eg. found during regression or PR testing)
2d. Reported on a PR
2z. Other:
Who reported the bug:
3a. Expensify user
3b. Expensify employee
3c. Contributor
3d. QA
3z. Other:
[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: I think this was a missed case and was not able to pinpoint a particular PR that caused this.
[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: N/A
[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 Jul 27, 2025
Triggered auto assignment to @sonialiap (
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.melvin-bot commentedon Aug 1, 2025
@sonialiap Huh... This is 4 days overdue. Who can take care of this?
[-]Expense - Split distance expense shows unexpected error with rate not valid &duplicate violation[/-][+][$250] Expense - Split distance expense shows unexpected error with rate not valid &duplicate violation[/+]melvin-bot commentedon Aug 4, 2025
Job added to Upwork: https://www.upwork.com/jobs/~021952393342401200146
melvin-bot commentedon Aug 4, 2025
Triggered auto assignment to Contributor-plus team member for initial proposal review - @allroundexperts (
External)huult commentedon Aug 5, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
Split distance expense shows unexpected error with rate not valid &duplicate violation
What is the root cause of that problem?
When we delete the old rate, the rate of the first/second expense will be out of policy because it was removed.
Continuing to click ‘More’ and splitting the expense using a rate that has been removed or is out of policy will result in a backend validation error, preventing the split.
Due to invalid data, the split expense incorrectly appears after the API call fails
App/src/libs/actions/IOU.ts
Line 12076 in 4d41b83
What changes do you think we should make in order to solve the problem?
To fix this issue, we should validate the distance rate before proceeding with the split. If the rate doesn’t exist or is disabled, we should display an error and return early.
App/src/libs/actions/IOU.ts
Line 11933 in 4d41b83
add this
const customUnitRateID = originalTransaction?.comment?.customUnit?.customUnitRateID; if (customUnitRateID && policy) { const customUnitRate = getDistanceRateCustomUnitRate(policy, customUnitRateID); // If the rate doesn't exist or is disabled, show an error and return early if (!customUnitRate || !customUnitRate.enabled) { const errorMessage = !customUnitRate ? 'iou.error.invalidRate' : 'iou.error.genericEditFailureMessage'; console.log('****** errorMessage ******', errorMessage); // Show error to user Onyx.merge(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${originalTransactionID}`, { errors: getMicroSecondOnyxErrorWithTranslationKey(errorMessage), }); return; } }and show this error in SplitExpensePage
App/src/pages/iou/SplitExpensePage.tsx
Line 68 in 46c3e9a
add
useEffect(() => { if (!draftTransaction?.errors) { return; } const errorKeys = Object.keys(draftTransaction.errors); if (errorKeys.length === 0) { return; } const firstErrorKey = errorKeys.at(0); if (!firstErrorKey) { return; } const errorText = draftTransaction.errors[firstErrorKey]; if (errorText) { // Error can be either a string or ReceiptError object const errorString = typeof errorText === 'string' ? errorText : errorText.source; setErrorMessage(errorString); } }, [draftTransaction?.errors]);App/src/pages/iou/SplitExpensePage.tsx
Line 70 in 46c3e9a
add:
if (draftTransaction?.errors) { clearSplitTransactionDraftErrors(transactionID); }App/src/pages/iou/SplitExpensePage.tsx
Line 74 in 46c3e9a
if (draftTransaction?.errors) { clearSplitTransactionDraftErrors(transactionID); }Screen.Recording.2025-08-05.at.12.20.46.mp4
Test branch
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
none
What alternative solutions did you explore? (Optional)
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.
Option 1:
We will automatically select a valid rate when splitting an expense
function getValidDistanceRate(policy: OnyxEntry<OnyxTypes.Policy>, originalRateID?: string): string | undefined { if (!policy?.customUnits) { return undefined; } const distanceUnit = getDistanceRateCustomUnit(policy); if (!distanceUnit?.rates) { return undefined; } // Check if the original rate is still valid and enabled if (originalRateID) { const originalRate = getDistanceRateCustomUnitRate(policy, originalRateID); if (originalRate?.enabled && originalRate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { return originalRateID; } } // Get the default rate (first rate created) if it's enabled const defaultRate = DistanceRequestUtils.getDefaultMileageRate(policy); if (defaultRate?.customUnitRateID && defaultRate.enabled) { const rate = getDistanceRateCustomUnitRate(policy, defaultRate.customUnitRateID); if (rate?.enabled && rate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { return defaultRate.customUnitRateID; } } // Find any enabled rate as fallback const enabledRates = Object.entries(distanceUnit.rates).filter(([, rate]) => rate.enabled && rate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); if (enabledRates.length > 0) { return enabledRates.at(0)?.[0]; // Return the first enabled rate ID } return undefined; }App/src/libs/actions/IOU.ts
Line 11969 in 4d41b83
add:
// If the original transaction is a distance request, ensure we use a valid rate if (originalTransaction && isDistanceRequestTransactionUtils(originalTransaction)) { const originalRateID = originalTransaction.comment?.customUnit?.customUnitRateID; const validRateID = getValidDistanceRate(policy, originalRateID); // If the original rate is invalid but we found a valid one, update the transaction params if (validRateID && validRateID !== originalRateID) { // Add customUnitRateID to transactionParams since it's a distance request (transactionParams as RequestMoneyTransactionParams).customUnitRateID = validRateID; } }Option 2:
The BE needs to be updated to not return a 402 when we split an expense with an invalid rate
43 remaining items
allroundexperts commentedon Sep 1, 2025
@sonialiap The second PR is not deployed to prod yet I think. Let's wait for it before the payment summary 😄
sonialiap commentedon Sep 1, 2025
Oh, whoops, I didn't realize there was a second
melvin-bot commentedon Sep 4, 2025
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.
melvin-bot commentedon Sep 4, 2025
@sonialiap Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
sonialiap commentedon Sep 5, 2025
Regression caused by #68820, has been fixed.
@allroundexperts looks like both PRs have been merged, is that correct? For payment, did we increase the scope of this issue or does the $250 sound reasonable for the work done?
allroundexperts commentedon Sep 8, 2025
I think it's reasonable.
sonialiap commentedon Sep 8, 2025
Payment summary:
50% reduction due to regression
allroundexperts commentedon Sep 8, 2025
BugZero Checklist:
Bug classification
Source of bug:
Where bug was reported:
Who reported the bug:
[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: I think this was a missed case and was not able to pinpoint a particular PR that caused this.
[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: N/A
[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/545410
Regression Test Proposal
Precondition:
Test:
Verify the app shows an error telling the user to select a valid rate and prevents splitting until a valid rate is chosen.
Do we agree 👍 or 👎
trjExpensify commentedon Jan 5, 2026
approved $125 for @allroundexperts.