medusa icon indicating copy to clipboard operation
medusa copied to clipboard

createRemoteLinkStep does not perform any compensation!

Open noubase opened this issue 1 year ago • 3 comments

Bug report

Describe the bug

createRemoteLinkStep does not perform any compensation!

System information

Medusa version (including plugins): v2.0.1 Node.js version: Database: Operating system: Browser (if relevant):

Steps to reproduce the behavior

parallelize(
          createRemoteLinkStep(links).config({name: 'link-medusa-order-and-packing-order'}),
          createPackingCollectionLines({orders, col_orders}),
          createPackingCollectionVariants(variantsInput),
      )

I have three parallel steps, and I specifically threw an error in the third one. My createPackingCollectionLines step compensates for the created data as expected, but the createRemoteLinkStep does not

Expected behavior

createRemoteLinkStep should dismiss the created links

noubase avatar Oct 28 '24 14:10 noubase

image image

I copied the code for this step locally, and somehow the createdLinks array is undefined within the compensation function, even though it was returned correctly at the end of the execution function.

noubase avatar Oct 28 '24 14:10 noubase

Alright, I dug in further and created a fourth, special error step that throws an error after 3000 ms

function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}

const errorStep = createStep(
    {name: 'error-step'},
    async () => {
      await sleep(3000)
      throw new Error('TEST')
    }
)

I added it to my parallelize block, and here’s what happened:

parallelize(
          createRemoteLinkStep(links).config({name: 'link-medusa-order-and-packing-order'}),
          createPackingCollectionLines({orders, col_orders}),
          createPackingCollectionVariants(variantsInput),
          errorStep()
      )

createRemoteLinkStep compensation input is undefined createPackingCollectionLines compensation input is ok, as expected createPackingCollectionVariants compensation input is undefined as well

Something strange is happening with the compensation input when using parallelize.

noubase avatar Oct 29 '24 14:10 noubase

Ok, guys. I finally find out what causes an issue When I remove .config({name: 'link-medusa-order-and-packing-order'}), everything works as expected. But you’re using config throughout your codebase.

noubase avatar Oct 29 '24 14:10 noubase

Hey @noubase , thank you for the report, I ll try to find out the issue here

adrien2p avatar Nov 04 '24 12:11 adrien2p

I found the issue and will open a pr in a short time 👍

adrien2p avatar Nov 04 '24 13:11 adrien2p

Here is the fix, let me know if you can try the snapshot but from the tests it should be good now

adrien2p avatar Nov 04 '24 13:11 adrien2p

Closing as it seems the bug was fixed already, please let us know if that's not the case

sradevski avatar Nov 22 '24 13:11 sradevski