Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[$250] QBD - Auto-sync toggle does not work correctly #52132

Open
2 of 8 tasks
lanitochka17 opened this issue Nov 6, 2024 · 42 comments
Open
2 of 8 tasks

[$250] QBD - Auto-sync toggle does not work correctly #52132

lanitochka17 opened this issue Nov 6, 2024 · 42 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Overdue

Comments

@lanitochka17
Copy link

lanitochka17 commented Nov 6, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.0.58-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/5184320
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause - Internal Team

Action Performed:

Precondition: QBD connection is established in the workspace.

  1. Navigate to Accounting
  2. Click on Advanced
  3. disable Auto-sync toggle
  4. Go back to Accounting and wait for the sync to finish return to Advanced

Expected Result:

Auto-sync toggle is disabled

Actual Result:

Auto-sync toggle returns to enabled after sync finishes

Workaround:

Unknown

Platforms:

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

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

Screenshots/Videos

Add any screenshot/video evidence
Bug6656487_1730891945304.Screen_Recording_2024-11-06_at_2.08.24_in_the_afternoon.1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021856102760605829790
  • Upwork Job ID: 1856102760605829790
  • Last Price Increase: 2024-11-11
  • Automatic offers:
    • suneox | Reviewer | 104920810
    • ikevin127 | Contributor | 104999271
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Nov 6, 2024
Copy link

melvin-bot bot commented Nov 6, 2024

Triggered auto assignment to @johncschuster (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 melvin-bot bot added the Overdue label Nov 11, 2024
@johncschuster johncschuster added the External Added to denote the issue can be worked on by a contributor label Nov 11, 2024
@melvin-bot melvin-bot bot changed the title QBD - Auto-sync toggle does not work correctly [$250] QBD - Auto-sync toggle does not work correctly Nov 11, 2024
Copy link

melvin-bot bot commented Nov 11, 2024

Job added to Upwork: https://www.upwork.com/jobs/~021856102760605829790

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 11, 2024
Copy link

melvin-bot bot commented Nov 11, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @suneox (External)

@melvin-bot melvin-bot bot removed the Overdue label Nov 11, 2024
@johncschuster
Copy link
Contributor

Triaged

@narefyev91
Copy link
Contributor

Hi, I'm Nicolay from Callstack - expert contributor group - and I would like to work on this issue.

Copy link

melvin-bot bot commented Nov 15, 2024

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

@melvin-bot melvin-bot bot added the Overdue label Nov 15, 2024
@ikevin127
Copy link
Contributor

I was able to reproduce / the issue happens on QBO as well. I will take over the issue from @suneox as C+ reviewer, coming from this Slack thread.

Let's go with @narefyev91 from expert contributor group as they've shown interest in fixing the issue!

🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Nov 15, 2024

Triggered auto assignment to @aldo-expensify, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@melvin-bot melvin-bot bot removed the Overdue label Nov 15, 2024
@aldo-expensify
Copy link
Contributor

Have we confirmed this a frontend issue?

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 15, 2024
Copy link

melvin-bot bot commented Nov 15, 2024

📣 @suneox 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@ikevin127
Copy link
Contributor

ikevin127 commented Nov 15, 2024

Have we confirmed this a frontend issue?

@aldo-expensify Looked into it and here's what happens:

When we turn Auto-sync off UpdateQuickbooksDesktopAutoSync is called -> returns response:

JSON
{
    "jsonCode": 200,
    "requestID": "8e31e2695c68cf1b-SJC",
    "onyxData": [
        {
            "key": "policy_E12DF2A9245F1530",
            "onyxMethod": "merge",
            "value": {
                "connections": {
                    "quickbooksDesktop": {
                        "config": {
                            "autoSync": {
                                "enabled": false,
                                "jobID": null
                            }
                        }
                    }
                }
            }
        }
    ],
    "previousUpdateID": 2960739932,
    "lastUpdateID": 2960747654
}

After QBD / QBO syncs, FE calls GetMissingOnyxMessages automatically -> which returns the following response that re-enables Auto-sync:

JSON
{
    "onyxData": [
        {
            "key": "policy_E12DF2A9245F1530",
            "onyxMethod": "merge",
            "value": {
                "connections": {
                    "quickbooksDesktop": {
                        "config": {
                            "autoSync": {
                                "enabled": true
                            }
                        }
                    }
                }
            }
        },
        {
            "key": "policy_E12DF2A9245F1530",
            "onyxMethod": "merge",
            "value": {
                "connections": {
                    "quickbooksDesktop": {
                        "config": {
                            "autoSync": {
                                "jobID": "9086846025541357"
                            }
                        }
                    }
                }
            }
        },
        {
            "key": "userMetadata",
            "onyxMethod": "set",
            "value": {
                "accountID": 15752938,
                "email": "[email protected]",
                "freeTrial": false,
                "planType": "corporate",
                "role": "admin",
                "tryNewDotDismissed": false
            }
        }
    ],
    "lastUpdateID": "2960783676",
    "previousUpdateID": "2960782355",
    "jsonCode": 200,
    "requestID": "8e31e7992b2f2536-SJC"
}

Looks like the first API call does not seem to persist the autoSync on the BE side which might have something to do with the fact that jobID is null for some reason which might mean that we don't pass it from FE when we make the call. What do you think ?

♻️ More context

function updateQuickbooksDesktopAutoSync<TSettingValue extends Connections['quickbooksDesktop']['config']['autoSync']['enabled']>(policyID: string, settingValue: TSettingValue) {
const onyxData = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICKBOOKS_DESKTOP_CONFIG.AUTO_SYNC, {enabled: settingValue}, {enabled: !settingValue});
const parameters: UpdateQuickbooksDesktopGenericTypeParams = {
policyID,
settingValue: JSON.stringify(settingValue),
idempotencyKey: String(CONST.QUICKBOOKS_DESKTOP_CONFIG.AUTO_SYNC),
};
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_DESKTOP_AUTO_SYNC, parameters, onyxData);
}

When we call the function in:

onToggle: (isOn: boolean) => QuickbooksDesktop.updateQuickbooksDesktopAutoSync(policyID, isOn),

as 2nd param (settingValue) we pass isOn (boolean) so looks like we don't pass any jobID which might be the root cause because if we follow settingValue's type we can notice QBDConnectionConfig:

App/src/types/onyx/Policy.ts

Lines 1286 to 1298 in 992e5d4

type QBDConnectionConfig = OnyxCommon.OnyxValueWithOfflineFeedback<{
/** API provider */
apiProvider: string;
/** Configuration of automatic synchronization from QuickBooks Desktop to the app */
autoSync: {
/** Job ID of the synchronization */
jobID: string;
/** Whether changes made in QuickBooks Desktop should be reflected into the app automatically */
enabled: boolean;
};

@aldo-expensify
Copy link
Contributor

aldo-expensify commented Nov 15, 2024

Looks like the first API call does not seem to persist the autoSync on the BE side which might have something to do with the fact that jobID is null for some reason which might mean that we don't pass it from FE when we make the call. What do you think ?

I don't think the frontend needs to send jobID: null, that shouldn't matter. There is some special code in the backend handling the job deleting and making that key null.

The steps described in the issue look incomplete

  1. Navigate to Accounting
  2. Click on Advanced
  3. disable Auto-sync toggle
  4. Go back to Accounting and wait for the sync to finish return to Advanced

I think first we should clear that up. Which case is it? What triggers the sync?

Case 1

  1. Navigate to Accounting
  2. Trigger the policy sync manually (NEW STEP!)
  3. Click on Advanced
  4. disable Auto-sync toggle
  5. Go back to Accounting and wait for the sync to finish return to Advanced

Case 2

  1. Navigate to Accounting
  2. Click on Advanced
  3. disable Auto-sync toggle
  4. Go back to Accounting
  5. Trigger the policy sync manually (NEW STEP!)
  6. Wait for the sync to finish return to Advanced

@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Nov 25, 2024
@aldo-expensify
Copy link
Contributor

Sorry, I haven't investigated again this. I'll give it some time tomorrow since I'm at the end of my day today.

@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Nov 29, 2024
Copy link

melvin-bot bot commented Dec 2, 2024

@johncschuster, @narefyev91, @ikevin127, @aldo-expensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@ikevin127
Copy link
Contributor

Not overdue, we're sorting out the issue.

@johncschuster
Copy link
Contributor

Bumping for Melv. Not overdue

@melvin-bot melvin-bot bot removed the Overdue label Dec 2, 2024
@aldo-expensify
Copy link
Contributor

I spent some time trying to debug this, but I have never seen the autoSync going back to enabled unless I touch it while a sync triggered by another field is still ongoing.

I even saw a GetMissingUpdates request after disabling the autoSync, but still the updates there didn't switch back the setting:

image

@aldo-expensify
Copy link
Contributor

aldo-expensify commented Dec 3, 2024

What I guess may be happening is something like this:

  1. Sync gets triggered somehow (according to reproduction steps, this shouldn't be happening)
  2. Integration server (IS) loads the policy data and starts communicating with QBO
  3. User changes a setting in NewDot (i.e. Auto sync). This queues a new sync waiting for the current one to finish.
  4. The IS finishes the sync that started in step 1 and sends a request the PHP to save the changes. The "changes" are outdated and don't include the latest setting value the user changed in step 3.
  5. The server saves the changes to the database and pushes updates to the clients.
  6. The user see the setting reverting

We could check if this is true when @ikevin127 reproduces by looking at the logs. If this is easy to reproduce for you, do you mind capturing the requestID of UpdateQuickbooksOnlineAutoSync when you disable "Auto sync" and also tell me your account's email and policyID?

As a solution, I guess we could make sure that the IS doesn't update advanced/import/export settings when it syncs data.

Copy link

melvin-bot bot commented Dec 4, 2024

@johncschuster @narefyev91 @ikevin127 @aldo-expensify this issue is now 4 weeks old, please consider:

  • Finding a contributor to fix the bug
  • Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
  • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

Thanks!

@melvin-bot melvin-bot bot added the Overdue label Dec 5, 2024
Copy link

melvin-bot bot commented Dec 6, 2024

@johncschuster, @narefyev91, @ikevin127, @aldo-expensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@ikevin127
Copy link
Contributor

@aldo-expensify Just retested and the issue is still reproducible on both QBO and QBD, tested both on dev / staging API.

Once the Auto-sync is turned off and the connection sync is completed -> if we wait long enough GetMissingOnyxMessages call is triggered (not sure by what) the Auto-sync will be turned back on.

App/src/libs/actions/App.ts

Lines 326 to 330 in 5f3782b

* Fetches data when the client has discovered it missed some Onyx updates from the server
* @param [updateIDFrom] the ID of the Onyx update that we want to start fetching from
* @param [updateIDTo] the ID of the Onyx update that we want to fetch up to
*/
function getMissingOnyxUpdates(updateIDFrom = 0, updateIDTo: number | string = 0): Promise<void | OnyxTypes.Response> {

GetMissingOnyxMessages is called on FE side in two places related to OnyxUpdateManager:

There were instances where GetMissingOnyxMessages was triggered shortly after connection sync is completed, and I also had instances where I had to wait 4-5 minutes for it to trigger, but when it does, it always turns Auto-sync back on.

Here are the details you asked for from my side - UpdateQuickbooksOnlineAutoSync:

{
    policyID: 18920FC1A9030899,
    email: "[email protected]",

    requestID: "8edefd622fd89648-SJC",
    lastUpdateID: 3280895077,
    previousUpdateID: 3269474291,
}

then after the one above, GetMissingOnyxMessages was called with this data ~3 minutes later:

{
    requestID: "8edf0bccaec123a9-SJC",
    lastUpdateID: "3280898069",
    previousUpdateID: "3280895077",
}

which turned Auto-sync back on as a result.

@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Dec 6, 2024
@aldo-expensify
Copy link
Contributor

Thanks @ikevin127 , I'll investigate again later this week with the information you provided 🙇

@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Dec 9, 2024
Copy link

melvin-bot bot commented Dec 13, 2024

@johncschuster, @narefyev91, @ikevin127, @aldo-expensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@johncschuster
Copy link
Contributor

How's this going, @aldo-expensify?

@melvin-bot melvin-bot bot removed the Overdue label Dec 13, 2024
@aldo-expensify
Copy link
Contributor

aldo-expensify commented Dec 13, 2024

Thanks for the ping.. investigating now:

I can confirm that the setting is being set to false in that request (disabling autoSync). I also see that since a setting was changed, we queue a job to run the policy integration sync. (Should we skip queueing a sync job if the setting that was change was autoSync=false?)

In those logs, I can see that the Integration Server is turning back on the autoSync setting. The only place that can happen for QBO I believe is here:

https://github.com/Expensify/Integration-Server/blob/c89f2fb0f140701543779a6069b309cf4f5af6b7/src/expensify/quickbooksonline/QuickbooksOnlineImporter.java#L217

So that narrows down the problem to figuring out why the Integration Server is considering that the policy has never been configured before.

@aldo-expensify
Copy link
Contributor

I'm trying to debug this further, but trying to connect a new QBO accounts redirects me to an invalid URL in dev, I don't know if there is a new bug or something else:

https://integrations.expensify.com.dev/Integration-Server/null?client_id=Q00XcQZaPUmMXcob
image

@ikevin127
Copy link
Contributor

@aldo-expensify This is a known issue, but you ca get around it by simply removing the .dev part from the link and proceed as usual.

@aldo-expensify
Copy link
Contributor

I'm pretty sure the issue is not the .dev, since I'm on purpose trying to work against the integration server running in my dev environment. The issue seems to be that /null which I'm not sure where is it coming from (the code has changed a lot since the last time I worked on this 🥲 ).

@aldo-expensify
Copy link
Contributor

There seems to be a problem with the Integration Server in my dev env, since the URL that ends up with /null is being constructed there

@ikevin127
Copy link
Contributor

I'm pretty sure the issue is not the .dev

Oh, yes - I confused it with what I'm doing when connecting QBO on DEV.

@melvin-bot melvin-bot bot added the Overdue label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Overdue
Projects
Status: Bugs and Follow Up Issues
Development

No branches or pull requests

6 participants