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 transaction support and add new Connection#transaction helper. #231
Fix transaction support and add new Connection#transaction helper. #231
Conversation
This fixes one of my major gripes that I had with tedious so far. I'd love to hear back what other people think who actually use or tried to use transactions with tedious. |
369415b
to
a2dbad3
Compare
I don't have a problem with the idea. Could you describe what you mean by possible breaking changes? Does that apply strictly to users who did nested transactions before? If so, how will this break that? |
Let me first describe the changes I made to some of the existing methods, and then I'll try to explain what I mean by "potentially breaking changes". I removed the Now, this never worked correctly, because nested transactions don't work like a stack in MS SQL. Here's a snippet from the documentation:
So, if you had nested transactions using tedious, and called I changed This means that
So, the potential breaking change would be that As you can see, none of the Again, all these changes make these methods work like what one would expect. On top of that, I hope that answers your question. 😄 |
On another note, I'll extend |
Sounds good to me. |
Ok, great. I'll try to wrap this up tomorrow. |
f168a64
to
824bac1
Compare
really looking forward to this making it in! |
824bac1
to
eb2c82f
Compare
So, this is basically ready and can be merged/released. @mbroadst Did you have any chance to take this on a test ride? |
great news ! |
@arthurschreiber I haven't test driven it yet, but we use tedious in sequelize and I can absolutely verify that transaction support is pretty broken in its current incarnation. Looking forward to giving this a shot in the next couple of days (as well as a few of your other PRs, like the stream based tokenizing). Thanks for the good work |
Can't wait to see the PR included in the master :) |
@arthurschreiber aren't you a collaborator? Just merge away my man 😄 |
@mbroadst I am, but just being a collaborator does not mean that I'll merge things willy-nilly. 😉 One more issue came up:
Example: connection.transaction(function() {
// Outer transaction has tedious.ISOLATION_LEVEL.READ_UNCOMMITTED
// Suppose doSomethingElse calls connection.transaction
// with tedious.ISOLATION_LEVEL.READ_COMMITTED
doSomethingElse(connection, function() {
// All queries executed here will be run with
// tedious.ISOLATION_LEVEL.READ_COMMITTED,
// even though they're run after the inner transaction
// finished.
});
}, tedious.ISOLATION_LEVEL.READ_UNCOMMITTED); Are we just going to say that whatever isolation level you set last is the one that is going to be valid until all transactions finished? |
On another note, Rails' ActiveRecord (which this feature is inspired from) raises an error if you try to set the isolation level on a nested transaction. Maybe we should do that too? |
One more issue: If you run into a batch aborting error (e.g. you try to create an already existing table inside a transaction), any rollback requests will fail (because the transaction was already rolled back). My idea here is to simply ignore these errors. The transaction is already rolled back, and there's nothing left for us to do. This also means that you should not try to "catch" RequestErrors coming from the connection helper, and treat transactions as "poisoned" if such an error is raised somewhere during the course of a transaction. |
eb2c82f
to
2a15873
Compare
I agree with your last two comments. I think they fit within the principle of least-surprise. |
eacc6b7
to
0f2fee4
Compare
This adds a new transaction helper that makes the use of transactions a breeze. It uses a mix of transactions and transaction savepoints to enable correctly nested transactions, while giving the user the ability to only roll back the contents of specific transaction blocks. This is a potential breakage for existing users that make use of `Connection#beginTransaction`, `Connection#rollbackTransaction` or `Connection#commitTransaction`, but these never worked correctly in the first place.
0f2fee4
to
ae7dc1c
Compare
I just squashed and pushed some additional changes:
I'll wait for the build to finish and will get this merged then. ✨ |
Let's 🚢 it! |
Fix transaction support and add new Connection#transaction helper.
I released this as 1.9.0. |
@mbroadst @nsilberman Any success with using this, so far? |
Documentation updates for #231 & 1.9.0 release.
This adds a new transaction helper that makes the use of transactions a
breeze. It uses a mix of transactions and transaction savepoints to
enable correctly nested transactions, while giving the user the ability
to only roll back the contents of specific transaction blocks.
This is a potential breakage for existing users that make use of
Connection#beginTransaction
,Connection#rollbackTransaction
orConnection#commitTransaction
, but these never worked correctly in thefirst place.
Fixes #152
As described in #152, the use of nested transactions is super broken in tedious in it's current form.
This PR adds
Connection#saveTransaction
to create transaction savepoints and uses that to build aConnection#transaction
helper that correctly employs transactions and savepoints to implement sane nested transaction handling.Example: