Skip to content

Cloud Spanner Client should prevent nested transactions #3476

@vkedia

Description

@vkedia

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 outer database.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 to database.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

Metadata

Metadata

Labels

api: spannerIssues related to the Spanner API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.release blockingRequired feature/issue must be fixed prior to next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions