OpenFn / adaptors

The new home for OpenFn adaptors; re-usable connectors for the most common DPGs and DPI building blocks.
GNU General Public License v3.0
4 stars 8 forks source link

Inconsistent behavior with `cursor` function syntax #596

Open mtuchi opened 1 month ago

mtuchi commented 1 month ago

Description:

I encountered an issue with the cursor function where two syntactically similar usages produce different results. The first usage works as expected, while the second one does not.

Working Code:

cursor((state) => state.manualCursor, { defaultValue: (state) => state.lastRunDateTime || 'now' })

CLI logs for working code

[CLI] ♦ Versions:
         ▸ node.js                    18.17.1
         ▸ cli                        1.2.2
         ▸ @openfn/language-common    monorepo
[CLI] ✔ Loading adaptors from monorepo at /Users/openfn/Workspace/adaptors
[CLI] ⚠ Skipping auto-install as monorepo is being used
[CLI] ✔ Loaded state from tmp/state.json
[CLI] ✔ Compiled all expressions in workflow
Setting cursor "now" to: 16:06 4 Jun 2024 (GMT+3)
[R/T] ✔ Completed step job-1 in 190ms
[CLI] ✔ State written to tmp/output.json
[CLI] ✔ Finished in 263ms ✨

Non-working Code:

cursor(state => state.manualCursor, state => ({
  defaultValue: state.lastRunDateTime || 'now'
}))

// Lazy load equivalent 
cursor($.manualCursor, { defaultValue: $.lastRunDateTime || 'now' });

CLI Logs for Non-working code


[CLI] ♦ Versions:
         ▸ node.js                    18.17.1
         ▸ cli                        1.2.2
         ▸ @openfn/language-common    monorepo
[CLI] ✔ Loading adaptors from monorepo at /Users/openfn/Workspace/adaptors
[CLI] ⚠ Skipping auto-install as monorepo is being used
[CLI] ✔ Loaded state from tmp/state.json
[CLI] ✔ Compiled all expressions in workflow
Setting cursor to: undefined
[R/T] ✔ Completed step job-1 in 246ms
[CLI] ✔ State written to tmp/output.json
[CLI] ✔ Finished in 318ms ✨

Steps to Reproduce:

  1. Run the job with working code with initial state as {}. It will print in CLI logs Setting cursor "now" to: HH:mm D M YYY
  2. Run the job with non-working code with initial state as {}. It will print in CLI logs Setting cursor "now" to: undefined