Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.34k stars 2.77k forks source link

[HOLD for payment 2023-09-08] Web - App Crashes when reloading after editing the Merchant #26181

Closed kbecciv closed 1 year ago

kbecciv commented 1 year ago

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Request money from user A
  2. Go the report
  3. Click on the Merchant to edit
  4. Clear the field and click on Save Notice 'removed the merchant (previously "Request")' message appears
  5. Refresh the page

Expected Result:

The app does not crash

Actual Result:

App crashes

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

Version Number: 1.3.58.0 Reproducible in staging?: y Reproducible in production?: n 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 Notes/Photos/Videos: Any additional supporting documentation

https://github.com/Expensify/App/assets/93399543/f99358ed-8157-4dc3-a36b-e28a8597bbff

https://github.com/Expensify/App/assets/93399543/8e18e9c3-6be8-494f-aa5f-fea7cabea6d1

Expensify/Expensify Issue URL: Issue reported by: @daveSeife Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1693277798912359

View all open jobs on GitHub

OSBotify commented 1 year ago

:wave: 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.
melvin-bot[bot] commented 1 year ago

Triggered auto assignment to @MariaHCD (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

mountiny commented 1 year ago

Merchant cannot be empty thats backend restriction, we probably need to add a validation here

Pujan92 commented 1 year ago

Proposal

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

Not validating the merchant field to be required(not reproducing crash on the dev env)

What is the root cause of that problem?

We don't have any validation to restrict empty value for the merchant.

Reason for a crash: When we refresh the money request report we receive incorrect structure by ReconnectApi call for reportActions which leads to the transaction undefined and accessing fields of undefined crashes the app.

https://github.com/Expensify/App/blob/3f9f1e6e2ce91468a536755f8d5830a2f77d7eaa/src/components/ReportActionItem/MoneyRequestView.js#L113

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

Add validate function and pass it to the the Form by setting the merchant as a required field.

https://github.com/Expensify/App/blob/3f9f1e6e2ce91468a536755f8d5830a2f77d7eaa/src/pages/EditRequestMerchantPage.js#L43-L45

https://github.com/Expensify/App/blob/3f9f1e6e2ce91468a536755f8d5830a2f77d7eaa/src/pages/iou/MoneyRequestMerchantPage.js#L121-L123

const validate = (values) => {
        const requiredFields = ['merchant'];
        const errors = ValidationUtils.getFieldRequiredErrors(values, requiredFields);
        return errors;
    }

Same needs to be done for MoneyRequestMerchantPage component by using the field name moneyRequestMerchant.

Provide the default value in the lodashGet pendingFields.fieldname for pendingAction prop which we are passing to OfflineWithFeedback in the MoneyRequestView component. 1, 2, 3, 4

MariaHCD commented 1 year ago

cc: @koko57 Please let us know what you find, thanks!

melvin-bot[bot] commented 1 year ago

⚠️ 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.

koko57 commented 1 year ago

@MariaHCD I couldn't reproduce it locally, I managed to reproduce it on staging so it's hard for me to tell for now what the exact RC is. I think that if we don't want to change the merchant to the empty string, the solution @Pujan92 proposes should work here

Pujan92 commented 1 year ago

I am able to reproduce the crash locally also due to incorrect orders bcoz whenever we refresh the money request report we won't get pendingFields in the api onyx response which causes the issue(accessing undefined of pendingFields).

MariaHCD commented 1 year ago

That makes sense, thanks @Pujan92.

One thing about your proposal:

Reason for a crash might be: Conditions are in the wrong order for all the fields here. First, we need to check for pendingAction availability in the transaction and then check for specific child fields.

Do you mean we first need to check for pendingFields in the transaction before trying to fetch any child fields?

Pujan92 commented 1 year ago

Yes @MariaHCD

Sorry, I made a mistake in thinking. We need to provide a default value for specific pendingFields considering the above reason bcoz we need to greyed out in any condition. I will update my proposal.

- {lodashGet(transaction, 'pendingFields.amount') || lodashGet(transaction, 'pendingAction')}
+ {lodashGet(transaction, 'pendingFields.amount', null) || lodashGet(transaction, 'pendingAction')}
MariaHCD commented 1 year ago

Okay, I was finally able to reproduce the issue on staging and saw the console error:

Screenshot 2023-08-29 at 5 13 51 PM

https://github.com/Expensify/App/assets/12268372/b3a17751-4e2f-4021-b619-4ba36c63998b

koko57 commented 1 year ago

looks like it doesn't see parentReportAction here

Pujan92 commented 1 year ago

Something fishy seems to be here, after a moment transactionID becomes 0(on refresh the report)

https://github.com/Expensify/App/blob/3f9f1e6e2ce91468a536755f8d5830a2f77d7eaa/src/components/ReportActionItem/MoneyRequestView.js#L176-L181

pradeepmdk commented 1 year ago

@koko57 looks like same https://github.com/Expensify/App/issues/26204

Pujan92 commented 1 year ago

I think reconnetApp api returns reportActions in the wrong structure. Needs to be an object but receiving array.

Screenshot 2023-08-29 at 19 43 57

That leads allReportActions to contain some incorrect structure entries which cause the transactionID to be 0. With that required transaction will be undefined and we try to access props on it which eventually crashes the app.

Screenshot 2023-08-29 at 19 47 42
Pujan92 commented 1 year ago

@MariaHCD @koko57 I think we do need to correct the structure in the BE for ReconnectApp api.

parasharrajat commented 1 year ago

I can not reproduce this issue on the main. I also think that merchant is removable otherwise why would we show removed?

Screenshot 2023-08-29 at 7 55 09 PM
koko57 commented 1 year ago

@parasharrajat I could reproduce it locally on main when I switched to using staging server

koko57 commented 1 year ago

and yeah, I agree with @Pujan92 that it should be checked on the BE as it happens not only for removing the merchant but also when editing other fields

Pujan92 commented 1 year ago

I can not reproduce this issue on the main. I also think that merchant is removable otherwise why would we show removed?

Even if we try to Save by clearing the input, it passes the previousValue(not the empty value) and returns some error message in response(Call to a member function getDisplayInformation() on null). https://github.com/Expensify/App/blob/4675db5348e305daca320f91066476344191d8d2/src/libs/TransactionUtils.js#L211-L213 I think we are showing based on the optimistic onyx data.

https://github.com/Expensify/App/assets/14358475/ad1f638d-92cd-418b-8b9f-f62904410b21

MariaHCD commented 1 year ago

I think reconnetApp api returns reportActions in the wrong structure. Needs to be an object but receiving array.

👀 Interesting, looking if something changed on the backend.

Screenshot 2023-08-29 at 6 55 34 PM

MariaHCD commented 1 year ago

From this other deploy blocker: https://github.com/Expensify/App/issues/26204

We're reverting this PR: https://github.com/Expensify/App/pull/25675

MariaHCD commented 1 year ago

Regarding the format of the report actions, I am checking this internal PR: https://github.com/Expensify/Web-Expensify/pull/38626

melvin-bot[bot] commented 1 year ago

⚠️ 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.

melvin-bot[bot] commented 1 year ago

⚠️ 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.

Pujan92 commented 1 year ago

@MariaHCD let me know if I need to work on the validation part that is mentioned here as saving empty merchant isn't working correctly.

luacmartins commented 1 year ago

Fix here - https://github.com/Expensify/Web-Expensify/pull/38665. This is not an App blocker, so gonna remove the label.

chiragsalian commented 1 year ago

Resolved on staging with a web-E CP. Closing issue. If it persists feel free to reopen.

Pujan92 commented 1 year ago

@chiragsalian aren't we supposed to fix the validation part of the merchant here?

daveSeife commented 1 year ago

@chiragsalian I can not repro the issue in the latest build. Reverting this https://github.com/Expensify/App/pull/25675 might have resolved the issue.

Am I eligible for reporting bones?

Pujan92 commented 1 year ago

@mountiny to confirm, do we need to add the required validations for the merchant field here?

melvin-bot[bot] commented 1 year ago

Triggered auto assignment to @trjExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

melvin-bot[bot] commented 1 year ago

Bug0 Triage Checklist (Main S/O)

mountiny commented 1 year ago

@daveSeife Yes

$250

daveSeife commented 1 year ago

@mountiny Okay. Thank you!

mountiny commented 1 year ago

Created a PR which will not allow empty merchants

trjExpensify commented 1 year ago

Cool, so confirming after that PR is merged we'll pay the reporting bonus of $250 for this issue only?

mountiny commented 1 year ago

@trjExpensify I think we can already pay out the reporting bonus $250, the crash is fixed now

trjExpensify commented 1 year ago

Okay, perfect. @daveSeife I've sent you an offer.

daveSeife commented 1 year ago

@trjExpensify Accepted the offer. Thank You!

trjExpensify commented 1 year ago

Perfect, paid!

melvin-bot[bot] commented 1 year ago

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

melvin-bot[bot] commented 1 year ago

The solution for this issue has been :rocket: deployed to production :rocket: in version 1.3.61-3 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 2023-09-08. :confetti_ball:

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

For reference, here are some details about the assignees on this issue:

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

melvin-bot[bot] commented 1 year ago

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: