-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
fix(medusa): ensure transaction is reused when service calls itself #6089
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Ignored Deployments
|
Nice catch 💪 you found that probably because there is somewhere where the service is not called within a transaction right? |
Should we fix this across the entire service? Think we use this pattern in a couple of other places |
Is it also the only service or should we check them all? |
@adrien2p, I will migrate the rest of the ProductService before we merge, but will keep the rest (if any) for a separate PR |
Sounds good to me, if the pr is not done just after we might need to create a ticket? |
@olivermrbl, @adrien2p - can we apply automerge or is there still more here? |
I ll do a final review, haven't seen the last commit. Butnif you want we can auto merge and if i have any comments we can handle them separately to not block it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🔥 couple of comments
@@ -594,7 +595,7 @@ class ProductService extends TransactionBaseService { | |||
) | |||
} | |||
|
|||
const result = await this.retrieve(product.id, { | |||
const result = await this.withTransaction(manager).retrieve(product.id, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: line 559 is missing. maybe we can do something like productServiceTx = this.withTransaction(manager)
and then use it in both places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srindom I ve seen that you have merged but there is still a missing transaction here
@@ -833,7 +834,7 @@ class ProductService extends TransactionBaseService { | |||
) | |||
} | |||
|
|||
const result = await this.retrieve(productId) | |||
const result = await this.withTransaction(manager).retrieve(productId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: same as the previous one to not recreate the instance multiple times everytime
What
Why
Explaination
What happens is the following:
ProductService.create
. This in turn callsatomicPhase
which sets theProductService.transactionManager_ = txForReqOne
txForReqOne
.ProductService.create
. This in turn callsatomicPhase
which sets theProductService.transactionManager_ = txForReqTwo
ProductService.create
wherethis.retrieve
is called. Because the ProductService is a singleton the retrieve call will attempt to usetxForReqTwo
to fetch the product.txForReqTwo
can't read the data oftxForReqOne
, the product is not found.