Repository navigation
Closed
Labels
released on @v7topic: clsFor issues and PRs. Everything that involves CLStype: bugDEPRECATED: replace with the "bug" issue type
Description
Issue Description
If using CLS to set a transaction, then the transaction is not received in the hooks.
What are you doing?
We set a transaction on the HTTP request using CLS. We expect the transaction to be available inside the hooks to be able to use the afterCommit transaction hook. However, options does not contain the transaction.
Here is the link to the SSCCE for this issue: LINK-HERE
This is inside a Koa2 app.
app.use(async (_, next) => {
await sequelize.transaction(() => next());
});In the model hook
beforeSave: (instance, options) => {
console.warn(options.transaction);
},The output is undefined.
What do you expect to happen?
options.transaction should be the same as the transaction set in the CLS.
What is actually happening?
options.transaction is undefined
undefined
Additional context
It appears that this logic is missing inside save:
Line 2289 in 83be13f
| if (options.transaction === undefined && this.sequelize.constructor._cls) { |
Adding this to save fixes this issue.
Environment
- Sequelize version: 6.4.0
- Node.js version: 12.20.0
- Operating System: Mac OSX
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start, but I don't know if this was left out intentionally
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Metadata
Metadata
Assignees
Labels
released on @v7topic: clsFor issues and PRs. Everything that involves CLStype: bugDEPRECATED: replace with the "bug" issue type
Activity
heroic commentedon Jan 24, 2021
Also discussed here #8585
heroic commentedon Jan 29, 2021
@papb could you take a look at this? I can raise a PR for this, is this is a miss and there is no real reason to have skipped passing the transaction to the hooks
github-actions commentedon Oct 27, 2021
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
heroic commentedon Oct 28, 2021
not stale
heroic commentedon Oct 28, 2021
@papb Any updates here?
github-actions commentedon Nov 6, 2021
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
heroic commentedon Nov 7, 2021
not stale
github-actions commentedon Nov 23, 2021
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
heroic commentedon Nov 23, 2021
not stale
WikiRik commentedon Nov 26, 2021
Sorry about the late response, it would be nice if you could make a PR for this @heroic
heroic commentedon Jan 9, 2022
@WikiRik Added!
github-actions commentedon Aug 7, 2022
🎉 This issue has been resolved in version 7.0.0-alpha.15 🎉
The release is available on:
Your semantic-release bot 📦🚀