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

salesforce Fix autoFetch in query #699

Merged
merged 19 commits into from
Jul 31, 2024
Merged

salesforce Fix autoFetch in query #699

merged 19 commits into from
Jul 31, 2024

Conversation

mtuchi
Copy link
Collaborator

@mtuchi mtuchi commented Jul 29, 2024

Summary

This PR contain a fix autoFetch and code improvements for salesforce query() function. All result records are now merged into records array

Ref #644

Review Checklist

Before merging, the reviewer should check the following items:

  • Does the PR do what it claims to do?
  • Are there any unit tests? Should there be?
  • Is there a changeset associated with this PR? Should there be? Note that
    dev only changes don't need a changeset.

@mtuchi mtuchi linked an issue Jul 29, 2024 that may be closed by this pull request
@mtuchi mtuchi marked this pull request as ready for review July 29, 2024 08:15
@mtuchi mtuchi requested a review from josephjclark July 29, 2024 08:21
@josephjclark
Copy link
Collaborator

@mtuchi this is targeted at main, not the salesforce epic. Is that right?

@josephjclark
Copy link
Collaborator

Ok, I think I get it.

In production, salesforce 4.8.1 will push an array of pages of results into state.references[]. So if there are two pages of data, you'll end up with something like this:

state.references: [
    [{
           done: true,
            totalSize: 6,
            records: [a, b, c],
    }, {
           done: true,
            totalSize: 6,
            records: [d, e, f],
    }]
]

The issue in #644 ins't necessarily a bug, just an unexpected design choice.

What this PR does is flattens those pages into a single item

state.references: [
    {
          done: true,
           totalSize: 6,
           records: [a, b, c, d, e, f],
    }
]

This still isn't the design I would choose, but we're fixing that in #691.

So this PR will fix the 4.x adaptor so that the old references design works a bit better, which is good for our legacy users.

But we'll need to port this fix over to the new 5.x branch.

Copy link
Collaborator

@josephjclark josephjclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protip: when writing tests, make a little hack to make them fail, then discard the hack.

packages/salesforce/src/Adaptor.js Outdated Show resolved Hide resolved
packages/salesforce/src/Adaptor.js Outdated Show resolved Hide resolved
packages/salesforce/test/Adaptor.test.js Show resolved Hide resolved
packages/salesforce/test/Adaptor.test.js Outdated Show resolved Hide resolved
packages/salesforce/test/Adaptor.test.js Outdated Show resolved Hide resolved
packages/salesforce/test/Adaptor.test.js Outdated Show resolved Hide resolved
packages/salesforce/test/Adaptor.test.js Outdated Show resolved Hide resolved
@mtuchi mtuchi requested a review from josephjclark July 30, 2024 08:47
});
})
.then(done)
.catch(done);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh don't call done() if there's an exception. If there's an exception we need this test to fail!

The same goes for the other tests in this describe block

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the .catch(done) for function in describe('query')

@josephjclark
Copy link
Collaborator

Hey, passing autofetch and autoFetch is pretty subtle and very easy to get wrong.

Can we maybe:
a) console.log whether we're going to autofetch
b) support both forms of autofetch

Copy link
Collaborator

@josephjclark josephjclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting closer, but still a few more changes. Thanks!

@mtuchi
Copy link
Collaborator Author

mtuchi commented Jul 31, 2024

I have made the suggested improvements, please have a look

@mtuchi mtuchi requested a review from josephjclark July 31, 2024 10:05
packages/salesforce/src/Adaptor.js Outdated Show resolved Hide resolved
packages/salesforce/src/Adaptor.js Outdated Show resolved Hide resolved
packages/salesforce/test/Adaptor.test.js Show resolved Hide resolved
packages/salesforce/test/Adaptor.test.js Outdated Show resolved Hide resolved
@@ -0,0 +1,8 @@
---
'@openfn/language-salesforce': major
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna call this a patch release.

it's technically a breaking fix.

But we have a major version coming soon which I expect jobs to migrate to. This patch just ensures that the 4.x branch is stable and behaves as originally intended.

@josephjclark josephjclark merged commit e806d5c into main Jul 31, 2024
2 checks passed
@josephjclark josephjclark deleted the 644-sf-autofetch branch July 31, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

salesforce: autofetch is broken
2 participants