-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Cloud Spanner Client should prevent nested transactions #3476
Comments
@tseaver This can wait until you have time to work on the Spanner integration tests. |
Note that this also is beta blocking. |
Can this be reopened? I don't think the fix actually fixes this. |
Reopened on behalf of @vkedia, so the remaining issues can be discussed further. |
I reviewed the code; it does exactly what it says on the tin. What is the problem exactly? |
The exact requirements are if someone calls |
There is a test that does this. |
It is not the same thing. That test is calling |
@tseaver I think I agree with Vikas here. The session checkout would still fundamentally allow... def bad_news():
database.run_in_transaction(unit_of_work)
database.run_in_transaction(bad_news)
|
@lukesneeringer FWIW, the callback passed to |
@tseaver Agreed, but we have no way to enforce that. In fairness, relying on this kind of weird scoping is uncommon in Python, so this entire issue is well into the edge case territory ("if someone aims a gun at their foot..."). Regardless, I will have a PR in a moment. |
Calling |
@lukesneeringer @tseaver I understand that we might have some false negatives, because we cannot catch all cases in which a nested transaction might be initiated. Are we avoiding all false positives (i.e. failing on a non-existent nested transaction)? I remember this was a concern in Node.js. |
Cloud Spanner does not support nested transactions. But the client library does allow users to call
database.run_in_transaction
inside of the callback that is provided to an outerdatabase.run_in_transaction
. This is misleading since users might believe that this will behave like a nested transaction but in reality these will be two independent transactions. This is confusing and a source of bugs. Specifically the inner transaction might succeed while the outer might ABORT, in which case the callback will be rerun thus rerunning the inner transaction.We should prevent this from happening by detecting and raising an error if someone calls
database.run_in_transaction
inside the callback provided todatabase.run_in_transaction
. Note that this needs to be done before Beta since this is a known breaking change.Also note that if we come across a use case where we do want to allow calling a nested
database.run_in_transaction
, we should be able to enable that in future without making a breaking change.cc @jgeewax @bjwatson
The text was updated successfully, but these errors were encountered: