Skip to content

ValueError: staleness option can't be changed while a transaction is in progress #192

@odino

Description

@odino

Environment details

  • OS: Linux uname -a 5.11.0-46-generic #51~20.04.1-Ubuntu
  • Language runtime version: Python 3.8.10
  • Package versions:
google-cloud-spanner        3.12.1              
sqlalchemy-spanner          1.0.0 
grpc-google-iam-v1          0.12.3              
grpcio                      1.42.0              
grpcio-status               1.42.0              
grpcio-tools                1.38.0 
google-api-client           3.14.159265359.post1
google-api-core             2.3.0               
google-api-python-client    2.0.2               
google-auth                 1.28.0              
google-auth-httplib2        0.1.0               
google-cloud-core           2.2.1               
googleapis-common-protos    1.53.0              
grpc-google-iam-v1          0.12.3

Steps to reproduce

Running this script:

from sqlalchemy import create_engine

engine = create_engine(
    "spanner:///projects/X/instances/Y/databases/Z"
)

print(engine.execute("SELECT 1").scalar())

ends up running the query, but also throwing an error -- output from the CLI:

Exception during reset or similar
Traceback (most recent call last):
  File "/home/alex/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 671, in _finalize_fairy
    fairy._reset(pool)
  File "/home/alex/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 847, in _reset
    pool.dispatch.reset(self, self._connection_record)
  File "/home/alex/.local/lib/python3.8/site-packages/sqlalchemy/event/attr.py", line 259, in __call__
    fn(*args, **kw)
  File "/home/alex/.local/lib/python3.8/site-packages/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py", line 51, in reset_connection
    dbapi_conn.connection.staleness = None
  File "/home/alex/.local/lib/python3.8/site-packages/google/cloud/spanner_dbapi/connection.py", line 203, in staleness
    raise ValueError(
ValueError: `staleness` option can't be changed while a transaction is in progress. Commit or rollback the current transaction and try again.
1

Now, if I use:

with engine.begin() as connection:
    print(sql(connection, "SELECT 1 + 1").scalar())

it's all good. Any idea?

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/python-spanner-sqlalchemy API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions