Skip to content

fix: don't rollback non-spanner connections on reset #709

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

Merged
merged 1 commit into from
Jun 27, 2025

Conversation

waltaskew
Copy link
Contributor

This is the simplest way to address bug #706 and address the AttributeError: 'Connection' object has no attribute 'rollback' I'm seeing when connections from BigQuery engines get caught by this event handler.

I think we should be able to rely on SQLAlchemy's reset on return behaviour to rollback transactions when they're reset rather than call rollback ourselves. That behaviour is also something end users can configure, so it'd be good to respect their settings if they disable the behaviour.

Fixes: #706

This is the simplest way to address bug googleapis#706 and address the
`AttributeError: 'Connection' object has no attribute 'rollback'`
I'm seeing when connections from BigQuery engines get caught by this
event handler.

I think we should be able to rely on SQLAlchemy's [reset on
return](https://docs.sqlalchemy.org/en/20/core/pooling.html#reset-on-return)
behaviour to rollback transactions when they're reset rather than call
rollback ourselves. That behaviour is also something end users can
configure, so it'd be good to respect their settings if they disable
the behaviour.

Fixes: googleapis#706
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API. label Jun 26, 2025
@olavloite olavloite changed the title bug: don't rollback non-spanner connections on reset fix: don't rollback non-spanner connections on reset Jun 27, 2025
@olavloite
Copy link
Contributor

@waltaskew small nit regarding commit messages / pull request titles: These are used to automatically trigger releases and generate the release notes. For that, we use Conventional Commits. The prefix that should be used for bug fixes is fix:. The bug: prefix will not trigger a new release, and will also not make the fix show up in the release notes.

@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 27, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 27, 2025
Copy link
Contributor

@olavloite olavloite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that Spanner should not do anything with non-Spanner connections. I've manually verified that the default behavior of SQLAlchemy is to rollback on reset. That default is being executed after this event handler has been executed, meaning that non-Spanner connections get two rollback requests.

@olavloite olavloite requested a review from aakashanandg June 27, 2025 10:49
@olavloite olavloite merged commit 4f86eb3 into googleapis:main Jun 27, 2025
15 of 16 checks passed
@waltaskew
Copy link
Contributor Author

@waltaskew small nit regarding commit messages / pull request titles: These are used to automatically trigger releases and generate the release notes. For that, we use Conventional Commits. The prefix that should be used for bug fixes is fix:. The bug: prefix will not trigger a new release, and will also not make the fix show up in the release notes.

Got it -- sorry about that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spanner Dialect Handles Pool Reset Events for Other Databases
4 participants