Skip to content

Commit

Permalink
feat: support transaction and request tags in dbapi
Browse files Browse the repository at this point in the history
Adds support for setting transaction tags and request tags in dbapi.
This makes these options available to frameworks that depend on
dbapi, like SQLAlchemy and Django.

Towards #525
  • Loading branch information
olavloite committed Dec 9, 2024
1 parent 39a41d9 commit ff64c6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ def pre_exec(self):
if priority is not None:
self._dbapi_connection.connection.request_priority = priority

request_tag = self.execution_options.get("request_tag")
if request_tag:
self.cursor.request_tag = request_tag

def fire_sequence(self, seq, type_):
"""Builds a statement for fetching next value of the sequence."""
return self._execute_scalar(
Expand Down
4 changes: 3 additions & 1 deletion test/mockserver_tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def test_sqlalchemy_select1(self):
with engine.connect().execution_options(
isolation_level="AUTOCOMMIT"
) as connection:
results = connection.execute(select(1)).fetchall()
results = connection.execute(
select(1).execution_options(request_tag="my-tag")
).fetchall()
self.verify_select1(results)

def test_sqlalchemy_select_now(self):
Expand Down

0 comments on commit ff64c6e

Please sign in to comment.