Skip to content

[Due for payment 2025-02-27] [$250] Taxes - App crashes when trying to disable tax rate. #56158

Closed

Description

@IuliiaHerets

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.0.93-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Yes, repro on both
If this was caught during regression testing, add the test name, ID and link from TestRail: #55192
Email or phone of affected tester (no customers): applausetester+bm456@applause.expensifail.com
Issue reported by: Applause Internal Team
Device used: Android and IOS
App Component: Workspace Settings

Action Performed:

  1. Open the app
  2. Create a workspace
  3. Go to more features and enable taxes
  4. Go to taxes and disable Tax Rate 1

Expected Result:

App shouldn't crash

Actual Result:

App crashes

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

https://github.com/user-attachments/assets/0d63e0eb-d327-432e-a895-46c35a23bcce
Bug6729510_1738324887963!log.txt

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021889364840283872581
  • Upwork Job ID: 1889364840283872581
  • Last Price Increase: 2025-02-11
Issue OwnerCurrent Issue Owner: @abekkala

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jan 31, 2025
  2. melvin-bot commented on Jan 31, 2025

    @melvin-bot

    Triggered auto assignment to @abekkala (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.

  3. nkdengineer commented on Feb 3, 2025

    @nkdengineer
    Contributor

    Proposal

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

    App crashes

    What is the root cause of that problem?

    In native, after we reload the app and the first time we call setPolicyTaxesEnabled, allPolicies is undefined because the callback here isn't triggered before. So originalTaxes is an empty object

    const originalTaxes = {...policy?.taxRates?.taxes};

    Then the app crashes here

    isDisabled: !!originalTaxes[taxID].isDisabled,

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

    We should get the isDisabled safer

    isDisabled: !!originalTaxes[taxID]?.isDisabled,
    

    isDisabled: !!originalTaxes[taxID].isDisabled,

    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)

    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.

  4. melvin-bot commented on Feb 4, 2025

    @melvin-bot

    @abekkala Whoops! This issue is 2 days overdue. Let's get this updated quick!

  5. melvin-bot commented on Feb 6, 2025

    @melvin-bot

    @abekkala Huh... This is 4 days overdue. Who can take care of this?

  6. melvin-bot commented on Feb 10, 2025

    @melvin-bot

    @abekkala Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

  7. bernhardoj commented on Feb 11, 2025

    @bernhardoj
    Contributor

    Proposal

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

    App crashes when trying to disable tax rate after creating a new workspace.

    What is the root cause of that problem?

    This only happens when we open the tax rate page for the first time. No need to create a new workspace. When we toggle the tax, the policy here is undefined, so the taxes is undefined too.

    function setPolicyTaxesEnabled(policyID: string, taxesIDsToUpdate: string[], isEnabled: boolean) {
    const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
    const originalTaxes = {...policy?.taxRates?.taxes};

    So, when we try to access the tax isDisabled here, it will crash.

    isDisabled: !!originalTaxes[taxID].isDisabled,

    It's undefined because allPolicies is also undefined. This all happens after #53852. In #53852, we enable inlineRequires, so this top level code is not immediately evaluated when we named import it.

    import {clearTaxRateError, deletePolicyTaxes, setPolicyTaxesEnabled} from '@libs/actions/TaxRate';

    let allPolicies: OnyxCollection<Policy>;
    Onyx.connect({
    key: ONYXKEYS.COLLECTION.POLICY,
    waitForCollectionCallback: true,
    callback: (value) => (allPolicies = value),
    });

    It will only be evaluated when the imported function is called (doc). But when setPolicyTaxesEnabled is called, the onyx callback hasn't completed yet.

    function setPolicyTaxesEnabled(policyID: string, taxesIDsToUpdate: string[], isEnabled: boolean) {
    const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];

    This is one of the pitfall described on the doc linked above.

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

    We have a few options.

    First, instead of relying the policy data from Onyx.connect, we can pass the policy from the component because it's already available anyway.

    // policy instead of policyID
    function setPolicyTaxesEnabled(policy: OnyxEntry<Policy>
    
    // update all usages of policyID with policy.id
    

    Then pass the policy from the component.

    setPolicyTaxesEnabled(policyID, [taxID], value);

    OR

    We can disable inline requires in WorkspaceTaxesPage, but that means other import inline requires are also disabled.

    OR

    Import TaxRate without any module.

    import '@libs/actions/TaxRate'
    

    OR

    Create a file that contains the common onyx connection such as policy, import it like above in App.tsx and TaxRate can get the all policies data from that file. or we can get the policy data from PolicyUtils

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    N/A

  8. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Feb 11, 2025
  9. changed the title [-]Taxes - App crashes when trying to disable tax rate.[/-] [+][$250] Taxes - App crashes when trying to disable tax rate.[/+] on Feb 11, 2025
  10. melvin-bot commented on Feb 11, 2025

    @melvin-bot
  11. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Feb 11, 2025
  12. 29 remaining items

  13. melvin-bot commented on Feb 20, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.1-6 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-02-27. 🎊

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

  14. melvin-bot commented on Feb 20, 2025

    @melvin-bot

    @parasharrajat @abekkala @parasharrajat The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  15. abekkala commented on Feb 20, 2025

    @abekkala
    Contributor

    PAYMENT SUMMARY FOR FEB 27

    • Fix: @bernhardoj [$250, if no regressions] Payment via NewDot
    • PR Review: @parasharrajat [$250, if no regressions] Payment via NewDot
      please complete checklist
  16. moved this to Hold for Payment in #expensify-bugson Feb 25, 2025
  17. melvin-bot commented on Feb 27, 2025

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@abekkala)

    • I have verified the correct assignees and roles are listed above and updated the neccesary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1889364840283872581/hired)
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  18. parasharrajat commented on Feb 27, 2025

    @parasharrajat
    Member

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other: Issue from migration

    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:

    Regression Test Proposal

    Test:

    1. Create a workspace if you don't have one
    2. Open the workspace
    3. Enable tax if it's not enabled yet
    4. Open the tax page
    5. Toggle one of the tax
    6. Verify the page doesn't crash

    Do we agree 👍 or 👎

  19. bernhardoj commented on Feb 27, 2025

    @bernhardoj
    Contributor

    Requested in ND.

  20. abekkala commented on Feb 27, 2025

    @abekkala
    Contributor

    posting again for better visibility for payee:

    PAYMENT SUMMARY FOR FEB 27

    Thank you! 🎉

  21. moved this from Hold for Payment to Done in #expensify-bugson Feb 27, 2025
  22. parasharrajat commented on Mar 1, 2025

    @parasharrajat
    Member

    Payment requested as per #56158 (comment)

  23. JmillsExpensify commented on Mar 3, 2025

    @JmillsExpensify
    Contributor

    $250 approved for @parasharrajat

  24. JmillsExpensify commented on Mar 3, 2025

    @JmillsExpensify
    Contributor

    $250 approved for @bernhardoj

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.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions