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

Juanny g - transactions global session ver #2839

Merged

Conversation

bagerard
Copy link
Collaborator

@bagerard bagerard commented Sep 4, 2024

Rework on top of original PR (#2569) with minor additional commits

Still lots of questions...
* Maintain state of session when entering and exiting transaction
* Update any collection methods used in mongoengine that accept session
* Update any database methods used in mongoengine that accept session
* Cascades should be accounted for as those methods are wrappers which call the
  same low-level pymongo colletion APIs updated above
* Any signals that try to read or write should also be wrapped in the
  transaction
* Mongo 3 doesn't support transactions
* Mongo 4 does, but 4.4 specifically started allowing colleciton creation in a transaction
This update accounts for the fact that at least one workflow
runs against Mongo 4.0.23
pymongo added support for transactions in 3.7
Use an extension of `threading.locals` to handle initialized sessions within a
thread to ensure session isolation from other threads.

Also, given that pymongo supports nested sessions + nested transactions, I added
a deque to track the "current" session state and mimic this behavior.
juannyG and others added 19 commits November 4, 2023 12:24
pymongo documentation explicitly states the callback of `with_transaction`
should not start new transactions
It's not a context manager anymore!
Not a context mgr anymore
W/out --verbose argument, mongo4 would throw errors. Could not reproduce
locally and this was the only thing that would consistently work in the github
action.
@bagerard bagerard force-pushed the juannyG-transactions-global-session-ver branch 2 times, most recently from 3b91f90 to 7a61e1c Compare September 4, 2024 19:00
@bagerard bagerard force-pushed the juannyG-transactions-global-session-ver branch from 7a61e1c to 8feba86 Compare September 4, 2024 19:02
@bagerard
Copy link
Collaborator Author

bagerard commented Sep 4, 2024

@juannyG Please have a look at this one, it builds on top of your PR. I've commented the parts I reworked to ease your review, if all looks good to you, it will finally be good to go 🚀

@bagerard
Copy link
Collaborator Author

bagerard commented Sep 4, 2024

For future ref, one of the job failed with the famous intermittent "TransientTransactionError" https://github.com/MongoEngine/mongoengine/actions/runs/10708253155/job/29690122622#step:6:395

I suggest to move forward anyway and do any rework on top once merged (to avoid blocking your work any longer)

@juannyG
Copy link
Collaborator

juannyG commented Sep 4, 2024

For future ref, one of the job failed with the famous intermittent "TransientTransactionError" https://github.com/MongoEngine/mongoengine/actions/runs/10708253155/job/29690122622#step:6:395

I suggest to move forward anyway and do any rework on top once merged (to avoid blocking your work any longer)

Yeah - I saw that 😅. But as we now know, the tests are just like any other app and will have to have something baked in to handle that error. I'll start working on making sure the tests aren't flaky after we get the merge through 💪

Looks good! Nice catch with ensuring the commit goes through!

@bagerard bagerard merged commit 8d5a976 into MongoEngine:master Sep 6, 2024
20 checks passed
@bagerard
Copy link
Collaborator Author

bagerard commented Sep 6, 2024

Finally merged 🚀
I created a ticket for the flaky test
#2841

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants