You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 14, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on May 14, 2026. It is now read-only.
Most queries raise non-fatal ValueError: Transaction is already committed #103
Connection pool raises non-fatal exceptions for SELECT/INSERT transactions
Steps to Reproduce the Problem
fromsqlalchemyimportColumn, Integer, MetaData, select, Text, Table, create_engineproject_id='foo'instance_id='bar'database='baz'spanner_uri=f'spanner:///projects/{project_id}/instances/{instance_id}/databases/{database}'# Create a table with one `Text`-type columnengine=create_engine(spanner_uri)
metadata=MetaData(bind=engine)
t=Table("TestTable", metadata, Column("test_column", Text, nullable=False))
metadata.create_all(engine)
withengine.begin() asconn:
results=conn.execute(select([t.c.test_column])).fetchall()
print(results)
aderk@aderk ~/q/pyle (u/aderk/labdb-spanner)> python txn_bug.py
Exception during reset or similar
Traceback (most recent call last):
File "/usr/local/google/home/aderk/.virtualenvs/pyle/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 697, in _finalize_fairy
fairy._reset(pool)
File "/usr/local/google/home/aderk/.virtualenvs/pyle/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 893, in _reset
pool._dialect.do_rollback(self)
File "/usr/local/google/home/aderk/.virtualenvs/pyle/lib/python3.8/site-packages/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py", line 773, in do_rollback
dbapi_connection.rollback()
File "/usr/local/google/home/aderk/.virtualenvs/pyle/lib/python3.8/site-packages/google/cloud/spanner_dbapi/connection.py", line 267, in rollback
self._transaction.rollback()
File "/usr/local/google/home/aderk/.virtualenvs/pyle/lib/python3.8/site-packages/google/cloud/spanner_v1/transaction.py", line 113, in rollback
self._check_state()
File "/usr/local/google/home/aderk/.virtualenvs/pyle/lib/python3.8/site-packages/google/cloud/spanner_v1/transaction.py", line 68, in _check_state
raise ValueError("Transaction is already committed")
ValueError: Transaction is already committed
[]
What about google-cloud-spanner version? SQLAlchemy dialect is built on top of it, problem can be there. I'm using master/main branches in both repositories, and it works fine.
If you can check the type of the dbapi_connection arg passed into do_rollback() method on your machine to ensure my guess is right, that would be good. Otherwise you can wait for the fix.
Activity
IlyaFaer commentedon Aug 23, 2021
There was an attempt to fix the error in the PR #68, but something seems to be left to do there.
IlyaFaer commentedon Aug 23, 2021
@aderk, I can't reproduce the error yet.
What about
google-cloud-spannerversion? SQLAlchemy dialect is built on top of it, problem can be there. I'm usingmaster/mainbranches in both repositories, and it works fine.Still, I have a suspision.
dbapi_connectionarg accepted by thedo_rollback()method can be of two types. Usually, we do something like this to avoid errors:https://github.com/cloudspannerecosystem/python-spanner-sqlalchemy/blob/1c9be70f901ca016c357ced66fe258f01b694787/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py#L789-L792
But obviously it wasn't done in the
do_rollback()method and it works fine only with proxies, while in your case it's most likely aConnectionobject:https://github.com/cloudspannerecosystem/python-spanner-sqlalchemy/blob/1c9be70f901ca016c357ced66fe258f01b694787/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py#L796-L809
If you can check the type of the
dbapi_connectionarg passed intodo_rollback()method on your machine to ensure my guess is right, that would be good. Otherwise you can wait for the fix.aderk commentedon Aug 23, 2021
Thanks Ilya for the quick response!
In case it still matters:
google-cloud-spanner 3.7.0
I can confirm #106 fixes this issue on my machine! =D