-
Notifications
You must be signed in to change notification settings - Fork 67
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
save from Activerecord can commit external transactions #109
Comments
@federicoemartinez I think it would be better to introduce an def save(self, in_transaction=False):
if in_transaction:
self.session.add(self)
return self
# Rest of the code
..... . |
it is indeed related to that.
Which is basically your idea, but I think it makes more explicit the behavior of the flag. In my use case, I have been using my first approach it works, but I see why it might be a problem. I can try to create a PR if you want. |
Go ahead. I will review it as soon as it's ready. |
I have some code in a transaction:
both objects have the ActiveRecordMixin.
That code used to work, and even after going to sqlalchemy 2, it worked.
But now with sqlalchemy-mixins 2.0.3, the save method commits the transaction, even when it wasn't the save method who opened it and that code is broken. I was thinking if it makes sense to check whether there is an active transaction an in that case don't commit.
Something like this (of course more tidy):
I realized the same happens with delete
The text was updated successfully, but these errors were encountered: