Skip to content

Exception Raised On Connect in 1.11.0 #659

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

Closed
waltaskew opened this issue May 10, 2025 · 0 comments · Fixed by #662
Closed

Exception Raised On Connect in 1.11.0 #659

waltaskew opened this issue May 10, 2025 · 0 comments · Fixed by #662
Assignees
Labels
api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@waltaskew
Copy link
Contributor

Environment details

  • Programming language: python
  • OS: linux
  • Language runtime version: 3.12.2
  • Package version: 1.11.0
  • google-cloud-spanner version: 3.42.0

Steps to reproduce

engine = sqlalchemy.create_engine(
    "spanner+spanner:///..."
)

with engine.begin() as conn:

throws an exception. It looks like the issue is that the dialect now depends upon a newer version of google-cloud-spanner / the dbapi. This fixed the issue:

pip install --upgrade google-cloud-spanner

which took me from google-cloud-spanner-3.42.0 to google-cloud-spanner-3.54.0

So the required version appears to be somewhere between those two. Looks like the setup.py needs to be updated to state the new required version.

Traceback (most recent call last):
  File "/p.py", line 7, in <module>
    with engine.begin() as conn:
  File "/opt/python3.12.2/lib/python3.12/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 3238, in begin
    with self.connect() as conn:
         ^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 3274, in connect
    return self._connection_cls(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 146, in __init__
    self._dbapi_connection = engine.raw_connection()
                             ^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 3298, in raw_connection
    return self.pool.connect()
           ^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 449, in connect
    return _ConnectionFairy._checkout(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 1264, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 713, in checkout
    rec = pool._do_get()
          ^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get
    with util.safe_reraise():
  File "lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "lib/python3.12/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
    return self._create_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
    return _ConnectionRecord(self)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 675, in __init__
    self.__connect()
  File "lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 915, in __connect
    )._exec_w_sync_on_first_run(self.dbapi_connection, self)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/event/attr.py", line 483, in _exec_w_sync_on_first_run
    self(*args, **kw)
  File "lib/python3.12/site-packages/sqlalchemy/event/attr.py", line 497, in __call__
    fn(*args, **kw)
  File "lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 1916, in go
    return once_fn(*arg, **kw)
           ^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/engine/create.py", line 752, in first_connect
    dialect.initialize(c)
  File "lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 536, in initialize
    self.default_isolation_level = self.get_default_isolation_level(
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 587, in get_default_isolation_level
    return self.get_isolation_level(dbapi_conn)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py", line 1734, in get_isolation_level
    level = conn.isolation_level
            ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Connection' object has no attribute 'isolation_level'
@waltaskew waltaskew added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels May 10, 2025
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API. label May 10, 2025
waltaskew added a commit to waltaskew/python-spanner-sqlalchemy that referenced this issue May 15, 2025
The library now depends on google-cloud-spanner-3.54.0 for transaction
isolation level support.

fixes googleapis#659
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. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants