Skip to content

fix: pass CLS transaction to model hooks - #13927

Merged
WikiRik merged 3 commits into
sequelize:mainfrom
galaxycard:main
Jul 9, 2022
Merged

WikiRik merged 3 commits into
sequelize:mainfrom
galaxycard:main

Conversation

@heroic

@heroic heroic commented Jan 9, 2022

Copy link
Copy Markdown
Contributor

Pull Request Checklist

Please make sure to review and check all of these items:

  • Have you added new tests to prevent regressions?
  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description Of Change

Fixes: #12973

Todos

  • Figure out how and where to write a test case to prevent future regression.

@ephys

ephys commented Jan 9, 2022

Copy link
Copy Markdown
Member

Thank you for the PR :)
Could you add a test in (i think) test/integration/cls.test.js that checks the transaction is properly passed where it wasn't before?

@ephys ephys added the type: bug DEPRECATED: replace with the "bug" issue type label Jan 9, 2022
@heroic

heroic commented Jan 9, 2022

Copy link
Copy Markdown
Contributor Author

Hi @ephys I tried! Couldn't figure out how to make it work though. I did test the change manually in our app though. Happy to give it a shot if you can guide.

@ephys ephys self-assigned this Jan 11, 2022
@ephys

ephys commented Jan 11, 2022

Copy link
Copy Markdown
Member

I'll try to take a stab at it next time I can

@ephys

ephys commented Jan 12, 2022 •

Copy link
Copy Markdown
Member

I'm looking into this more and it's weird that your fix is necessary.

Model#save calls either QueryInterface#insert or QueryInterface#update depending on Model#isNewRecord.
Both of these methods then call Sequelize#query, which retrieves the transaction from Sequelize._cls.

Edit: nevermind it's not about query it's about the hook. 🤦‍♀️
It's early.

@ephys

ephys commented Jan 12, 2022 •

Copy link
Copy Markdown
Member

I've added tests for this in branch feature/ephys/cls-in-hooks

Here they are: https://github.com/sequelize/sequelize/blob/feature/ephys/cls-in-hooks/test/integration/cls.test.js#L143
And the commit: 6294414

Feel free to copy them in your PR / to cherry pick the commit

It tests every Model hooks:
image

Comment thread test/integration/cls.test.js Resolved
@heroic

heroic commented Jan 13, 2022

Copy link
Copy Markdown
Contributor Author

@ephys Still fails. Do you know why?

@ephys

ephys commented Jan 13, 2022

Copy link
Copy Markdown
Member

Well passing the transaction to hooks has been implemented in the #save method but the other model methods aren't implementing it

image

@heroic

heroic commented Jan 17, 2022

Copy link
Copy Markdown
Contributor Author

Well passing the transaction to hooks has been implemented in the #save method but the other model methods aren't implementing it

image

So we'll need to pass the transaction in other functions too. Got it. Will update

@ephys ephys changed the title fix: sequelize should take transaction from CLS everywhere fix: pass CLS transaction to model hooks Jan 26, 2022
@WikiRik

WikiRik commented Jan 31, 2022

Copy link
Copy Markdown
Member

Hi @heroic, did you get a chance to look at this again? Or is there something we can do to help?

@heroic

heroic commented Jan 31, 2022

Copy link
Copy Markdown
Contributor Author

@WikiRik a colleague of mine is looking to get this closed! We should have this working soon

@AmirMelio

Copy link
Copy Markdown

@WikiRik a colleague of mine is looking to get this closed! We should have this working soon

Hi @heroic , any update?

@joker00777

joker00777 commented May 30, 2022 •

Copy link
Copy Markdown
Contributor

Hi @AmirMelio I will be continuing it from here.

Comment thread test/integration/cls.test.js Resolved

@joker00777 joker00777 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test file typo

@joker00777
joker00777 force-pushed the main branch 2 times, most recently from 7758520 to e1d4dc2 Compare June 2, 2022 05:03
Comment thread test/integration/cls.test.js Resolved

@joker00777 joker00777 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

any idea why these are failing?

Comment thread lib/model.js Resolved
Comment thread test/integration/cls.test.js Resolved
Comment thread test/integration/cls.test.js Resolved

@joker00777 joker00777 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for the late response : (

Comment thread test/integration/cls.test.js Resolved
Comment thread test/integration/cls.test.js Resolved
@WikiRik

WikiRik commented Jun 13, 2022

Copy link
Copy Markdown
Member

GitHub has issues with the caching today, I'll rerun the checks after they have solved that incident.

Comment thread src/model-internals.ts Resolved
@joker00777

Copy link
Copy Markdown
Contributor

@ephys any updates?

@joker00777

Copy link
Copy Markdown
Contributor

@ephys waiting for your feedback : )

@ephys
ephys self-requested a review June 21, 2022 05:31
@joker00777

Copy link
Copy Markdown
Contributor

@ephys can we merge it now : ) ?

@WikiRik
WikiRik requested a review from ephys June 24, 2022 10:49

@ephys ephys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are a few unresolved comments from the previous review :)

Comment thread test/integration/cls.test.js Resolved
@joker00777
joker00777 force-pushed the main branch 4 times, most recently from e8d2346 to aeecb25 Compare July 6, 2022 14:28
@joker00777

Copy link
Copy Markdown
Contributor

Hey @ephys can you take a look now?

@ephys
ephys self-requested a review July 8, 2022 13:41
@ephys

ephys commented Jul 8, 2022

Copy link
Copy Markdown
Member

This is great :) There are two remaining comments and then this is ready to merge:

Could you enable the option to allow maintainers to add commits on your branch once you are ready? We use it to update the branch before merging.

@heroic

heroic commented Jul 8, 2022

Copy link
Copy Markdown
Contributor Author

Hi @ephys, since the fork is owned by an org, there isn't an option to enable Allow edits by maintainers. We can add the maintainers write access on the repo by adding them individually. Would that work?

@ephys

ephys commented Jul 9, 2022 •

Copy link
Copy Markdown
Member

I think we can try coordinating. If you can click the "update branch" button then @ me and/or @WikiRik, I'll merge this immediately before another PR

@joker00777

Copy link
Copy Markdown
Contributor

@ephys @WikiRik update branch Done : )

@WikiRik

WikiRik commented Jul 9, 2022

Copy link
Copy Markdown
Member

@joker00777 we accidentally merged something else just now, could you update the branch once again?

@ephys

ephys commented Jul 9, 2022 •

Copy link
Copy Markdown
Member

Sorry 😅

@joker00777

Copy link
Copy Markdown
Contributor

haha done @WikiRik @ephys ; )

@WikiRik

WikiRik commented Jul 9, 2022

Copy link
Copy Markdown
Member

Thanks! After the tests pass, I'll merge this

@joker00777

Copy link
Copy Markdown
Contributor

Thank You : )

@WikiRik
WikiRik merged commit be98856 into sequelize:main Jul 9, 2022
@WikiRik

WikiRik commented Jul 9, 2022

Copy link
Copy Markdown
Member

There we go! Thanks again for working on this @joker00777 @heroic

@github-actions

github-actions Bot commented Aug 7, 2022

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 7.0.0-alpha.15 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released on @v7 type: bug DEPRECATED: replace with the "bug" issue type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hooks do not get CLS transaction

5 participants