Closed kavimuru closed 8 months ago
Triggered auto assignment to @laurenreidexpensify (Bug
), see https://stackoverflow.com/c/expensify/questions/14418 for more details.
Job added to Upwork: https://www.upwork.com/jobs/~017a49b283451a8f08
Triggered auto assignment to Contributor-plus team member for initial proposal review - @thesahindia (External
)
"The receipt didn't upload.." error message appears when create Scan expense with PDF file.
Note: this only happens on Android for files which have empty spaces in their names.
In .../AttachmentPicker/index.native.js
within the getDataForUpload
function in fileResult object we pass uri: fileData.fileCopyUri || fileData.uri and on Android the sources look like this:
file:///data/user/0/com.expensify.chat.dev/cache/e22200b8-5380-47ea-9fea-f57ca9ad5b8d/cb%20copy.pdf
content://com.android.providers.media.documents/document/document%3A1000000037
currently the first one is used on Android which is a cached reference to the file which while it does work for preview purposes, when the RequestMoney
call is made with the cached source the request fails right away because the path doesn't contain the actual file.
Using fileData.uri
fixes the issue of the RequestMoney
call failing because on Android fileData.uri is the real path to the actual file instead of a cached reference path.
Given that the issue is present only on Android, we can either use Platform.select with android changed to fileData.uri only while maintaining fileData.fileCopyUri || fileData.uri for ios where the issue is not present. Or create a custom library @lib
where we will have index.ts noop
and index.android.ts and index.ios.ts that return the fileResult.uri accordingly.
Not overdue, Melvin being a bit harsh with the weekend clock
Won't be able to take this. Please reassign.
I am interested in reviewing this
๐ฃ @situchan ๐ An offer has been automatically sent to your Upwork account for the Contributor role ๐ Thanks for contributing to the Expensify app!
Offer link Upwork job Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review ๐งโ๐ป Keep in mind: Code of Conduct | Contributing ๐
@situchan ready for review thanks
@ikevin127 thanks for the proposal. Your RCA doesn't explain why this bug happens only on files which have spaces.
@situchan The root cause of the issue only happening on Android for files which have spaces in their names is that the fileCopyUri
cache path of the file with spaces is url encoded which replaces empty spaces with %20
instead of empty space ` which when passed to the
RequestMoney` endpoint, the path is corrupt.
Example: if in the function getDataForUpload
before the if's we add:
RNFetchBlob.fs.stat(decodeURIComponent(fileData.fileCopyUri)).then((stats) => console.log('STATS', stats)).catch((error) => console.log('ERROR', error));
we can see that we get the STATS console.log('STATS', stats)
and not ERROR if we decode the fileData.fileCopyUri
compared to running the code block without decoding it which throws error: failed to stat path '/data/user/0/com.expensify.chat.dev/cache/3ab77e4f-9f84-4fa7-8566-8a7a4a2fec45/cb%20copy.pdf' because it does not exist or it is not a folder
.
Even though I could confirm this, sending the decoded fileData.fileCopyUri
to the RequestMoney
request, the request still fails. But using fileData.uri
absolute path on Android fixes the issue.
This is all I can say as to why this edge case when using fileCopyUri
cached path vs uri
absolute path to the actual file. I could not find any explanation of this edge case anywhere online nor could I find any source code which would explain why this is the case.
๐ฃ It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? ๐ธ
Still waiting for proposals
๐ฃ It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? ๐ธ
@situchan could you review the feedback above?
The root cause is still not clear from the last comment above. I was looking for the solution with keeping fileCopyUri || uri
as this already works perfect on iOS.
Indeed it does work on iOS - meaning this is an Android specific issue for which I wasn't able to find more context to explain the root cause as to why this edge case is happening for files with spaces in their names when using fileCopyUri
on Android: Native ๐
What we can do to solve this issue while maintaining the current iOS specific logic unchanged, as mentioned in the solution:
create a custom library @lib where we will have index.ts
noop
andindex.android.ts
andindex.ios.ts
that return the fileResult.uri accordingly.
meaning for Android we return the uri
whereas for iOS we return fileData.fileCopyUri || fileData.uri
just like we currently do for both.
If this is enough in order to move forward with fixing the issue, I'm available to raise a PR immediately ๐
@laurenreidexpensify, @situchan Whoops! This issue is 2 days overdue. Let's get this updated quick!
still looking for alternative solution
@laurenreidexpensify @situchan this issue is now 3 weeks old. There is one more week left before this issue breaks WAQ and will need to go internal. What needs to happen to get a PR in review this week? Please create a thread in #expensify-open-source to discuss. Thanks!
๐ฃ It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? ๐ธ
Upwork job price has been updated to $1000
increased bounty
How does scan receipt get uploaded?
At the scan step, we use picker to open an attachment. Once the attachment is available, setReceiptAndNavigate
is called here for native devices to set the receipt details in the transaction draft and, further, navigate to the confirmation
step. Now, on component mount of the confirmation step, we check if the scan receipt is available here. And, if available, we set the receipt File object setReceiptFile
which is later used in money request generation here. The API request would add the receipt File object via FormData which will trigger the upload of receipt file
What is going wrong here?
Everything goes well for Android native devices until the check for scan receipt availability here in the confirmation step. navigateToStartStepIfScanFileCannotBeRead
internally makes use of readFileAsync
here to fetch the receipt File object. However, when the file name contains space
on android native devices, the File type
is empty here which results in failure of receipt upload operation and the resultant error message.
To fix this, we can set the File type correctly here. Reading the file and determining the correct type
works fine even when space
is present within file name here. So, we can preserve the identified File type
within transactionโs receipt
here and use the type
in confirmation step like this:
Add receiptType
here
const receiptType = lodashGet(transaction, 'receipt.type');
Pass receiptType
to navigateToStartStepIfScanFileCannotBeRead
here
IOU.navigateToStartStepIfScanFileCannotBeRead(receiptFilename, receiptPath, onSuccess, requestType, iouType, transactionID, reportID, receiptType);
Pass receiptType
to readFileAsync
here
FileUtils.readFileAsync(receiptPath, receiptFilename, onSuccess, onFailure, receiptType);
Finally, set the File type
if blob.type
is not valid whereas we could still retrieve the blob itself here
const file = new File([blob], cleanFileName(fileName), {type: blob.type ? blob.type : fileType});
Additionally, we also need to pass receiptType
to navigateToStartStepIfScanFileCannotBeRead
in IOURequestStepParticipants
as we do for IOURequestStepConfirmation
to support the global FAB flow here
Triggered auto assignment to @AndrewGable, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
@AndrewGable bump to assign if you agree with proposal
@AndrewGable @laurenreidexpensify @situchan this issue is now 4 weeks old and preventing us from maintaining WAQ, can you:
Thanks!
Current assignee @situchan is eligible for the Internal assigner, not assigning anyone new.
@AndrewGable, @laurenreidexpensify, @situchan Eep! 4 days overdue now. Issues have feelings too...
@AndrewGable bump ^ ^
The automatic offers did not get generated here. Looks like the default flow got disrupted somewhere. cc @laurenreidexpensify
Reviewing
label has been removed, please complete the "BugZero Checklist".
The solution for this issue has been :rocket: deployed to production :rocket: in version 1.4.45-6 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2024-03-07. :confetti_ball:
For reference, here are some details about the assignees on this issue:
BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
Payment Summary:
C+ - @situchan $1000 offer sent in Upwork Contributor - @rojiphil $1000 offer sent in Upwork
This is not recent regression. The bug existed for long time. As this was reported by QA team, we can skip regression test.
@laurenreidexpensify I accepted new offer. You can close old contract
Contributor - @rojiphil $1000 offer sent in Upwork
@laurenreidexpensify I accepted the new offer. Thanks.
Payment Summary:
upwork.com/ab/applicants/1765716251259191296/job-details C+ - @situchan $1000 paid in Upwork Contributor - @rojiphil $1000 paid in Upwork
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: 1.4.24-4 Reproducible in staging?: y Reproducible in production?: y If this was caught during regression testing, add the test name, ID and link from TestRail: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: Applause internal team Slack conversation:
Action Performed:
Expected Result:
"The receipt didn't upload.." error message must not be appeared when user create Scan expense with PDF file.
Actual Result:
"The receipt didn't upload.." error message appears when create Scan expense with PDF file.
Workaround:
unknonw
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
Add any screenshot/video evidence
https://github.com/Expensify/App/assets/43996225/8304394e-3c8c-4926-8009-f89c365518d8
View all open jobs on GitHub
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @laurenreidexpensify