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

feat(utils): Introduce promiseAll util #5543

Merged
merged 27 commits into from
Nov 8, 2023
Merged

Conversation

adrien2p
Copy link
Member

@adrien2p adrien2p commented Nov 3, 2023

What
Promise.all with typeorm transaction does not play well in case of nesetd promises. A rejection does not necessarely rollback all queries since the nested promises will run on an orphan transaction resulting in them being commited. This utils aim to replace all promise.all usage

Copy link

changeset-bot bot commented Nov 3, 2023

🦋 Changeset detected

Latest commit: de32729

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@medusajs/medusa Patch
@medusajs/inventory Patch
medusa-fulfillment-webshipper Patch
medusa-plugin-brightpearl Patch
medusa-plugin-contentful Patch
medusa-source-shopify Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Nov 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Visit Preview Nov 6, 2023 6:39pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview Nov 6, 2023 6:39pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Nov 6, 2023 6:39pm

@adrien2p
Copy link
Member Author

adrien2p commented Nov 3, 2023

@olivermrbl @carlos-r-l-rodrigues what do you think about it?

@adrien2p
Copy link
Member Author

adrien2p commented Nov 3, 2023

I ve done an example with the order service, let see the tests

@adrien2p adrien2p marked this pull request as ready for review November 3, 2023 13:51
@adrien2p adrien2p requested a review from a team as a code owner November 3, 2023 13:51
@adrien2p
Copy link
Member Author

adrien2p commented Nov 3, 2023

If we agree on the approach, then we can start fixing all the places

Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues left a comment

Choose a reason for hiding this comment

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

LGTM

packages/utils/src/common/promise-all.ts Outdated Show resolved Hide resolved
@adrien2p
Copy link
Member Author

adrien2p commented Nov 3, 2023

should we update all places if everybody aggree?

@adrien2p
Copy link
Member Author

adrien2p commented Nov 6, 2023

ps: I haven't changes everywhere if I thought it wasnt making too much sense

@adrien2p
Copy link
Member Author

adrien2p commented Nov 6, 2023

@olivermrbl I had to add the utils package as a dep in some plugins. Don't think it should be a problem for those. Though, I ve used the workspace:^ for the version. Let me know if you want me to change it

@olivermrbl
Copy link
Contributor

olivermrbl commented Nov 6, 2023

Perhaps, we should add a note on this in our troubleshooting section. Although, not directly related to Medusa, it would be good to be able to point somewhere in case developers experience similar issues working with our services.

cc @shahednasser

@shahednasser
Copy link
Member

Sure @olivermrbl , is there a bit more context to the exact problem or error that occurs (which makes it easier for people to find) and the proposed solution?

@olivermrbl
Copy link
Contributor

olivermrbl commented Nov 6, 2023

Aside from the original issue, this Typeorm issue and this SO submission do a good job of explaining the issue succinctly. I don't think we need to go into depth about how promise.All works, so maybe just highlight that if you are experiencing issues rolling back DB transactions when running multiple promises with promise.All, this might be why.

@shahednasser
Copy link
Member

Sure, but a troubleshooting guide should provide some direction for a solution, could be just an alternative of using Promise.all. Do we have some kind of advice to provide people running into then issue?

@olivermrbl
Copy link
Contributor

olivermrbl commented Nov 6, 2023

Do we have some kind of advice to provide people running into then issue?

My bad, I should have mentioned this previously. We should recommend the util function introduced in this PR promiseAll from @medusajs/utils

@adrien2p adrien2p requested a review from olivermrbl November 7, 2023 08:42
@olivermrbl olivermrbl merged commit f90ba02 into develop Nov 8, 2023
12 checks passed
@olivermrbl olivermrbl deleted the feat/utils-promise-all branch November 8, 2023 07:48
@github-actions github-actions bot mentioned this pull request Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants