Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 8ac7ba8

Browse files
committed
Merge branch 'main' into support-db-roles-in-connect
2 parents 1c13d2d + aae8d61 commit 8ac7ba8

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

google/cloud/spanner_dbapi/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ def connect(
805805
database = instance.database(
806806
database_id, pool=pool, database_role=database_role
807807
)
808-
conn = Connection(instance, database)
808+
conn = Connection(instance, database, **kwargs)
809809
if pool is not None:
810810
conn._own_pool = False
811811

tests/system/test_dbapi.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,9 @@ def test_execute_batch_dml_abort_retry(self, dbapi_database):
865865
self._cursor.execute("run batch")
866866
dbapi_database._method_abort_interceptor.reset()
867867
self._conn.commit()
868-
assert method_count_interceptor._counts[COMMIT_METHOD] == 1
869-
assert method_count_interceptor._counts[EXECUTE_BATCH_DML_METHOD] == 3
870-
assert method_count_interceptor._counts[EXECUTE_STREAMING_SQL_METHOD] == 6
868+
assert method_count_interceptor._counts[COMMIT_METHOD] >= 1
869+
assert method_count_interceptor._counts[EXECUTE_BATCH_DML_METHOD] >= 3
870+
assert method_count_interceptor._counts[EXECUTE_STREAMING_SQL_METHOD] >= 6
871871

872872
self._cursor.execute("SELECT * FROM contacts")
873873
got_rows = self._cursor.fetchall()
@@ -879,28 +879,28 @@ def test_multiple_aborts_in_transaction(self, dbapi_database):
879879

880880
method_count_interceptor = dbapi_database._method_count_interceptor
881881
method_count_interceptor.reset()
882-
# called 3 times
882+
# called at least 3 times
883883
self._insert_row(1)
884884
dbapi_database._method_abort_interceptor.set_method_to_abort(
885885
EXECUTE_STREAMING_SQL_METHOD, self._conn
886886
)
887-
# called 3 times
887+
# called at least 3 times
888888
self._cursor.execute("SELECT * FROM contacts")
889889
dbapi_database._method_abort_interceptor.reset()
890890
self._cursor.fetchall()
891-
# called 2 times
891+
# called at least 2 times
892892
self._insert_row(2)
893-
# called 2 times
893+
# called at least 2 times
894894
self._cursor.execute("SELECT * FROM contacts")
895895
self._cursor.fetchone()
896896
dbapi_database._method_abort_interceptor.set_method_to_abort(
897897
COMMIT_METHOD, self._conn
898898
)
899-
# called 2 times
899+
# called at least 2 times
900900
self._conn.commit()
901901
dbapi_database._method_abort_interceptor.reset()
902-
assert method_count_interceptor._counts[COMMIT_METHOD] == 2
903-
assert method_count_interceptor._counts[EXECUTE_STREAMING_SQL_METHOD] == 10
902+
assert method_count_interceptor._counts[COMMIT_METHOD] >= 2
903+
assert method_count_interceptor._counts[EXECUTE_STREAMING_SQL_METHOD] >= 10
904904

905905
self._cursor.execute("SELECT * FROM contacts")
906906
got_rows = self._cursor.fetchall()
@@ -921,8 +921,8 @@ def test_consecutive_aborted_transactions(self, dbapi_database):
921921
)
922922
self._conn.commit()
923923
dbapi_database._method_abort_interceptor.reset()
924-
assert method_count_interceptor._counts[COMMIT_METHOD] == 2
925-
assert method_count_interceptor._counts[EXECUTE_STREAMING_SQL_METHOD] == 6
924+
assert method_count_interceptor._counts[COMMIT_METHOD] >= 2
925+
assert method_count_interceptor._counts[EXECUTE_STREAMING_SQL_METHOD] >= 6
926926

927927
method_count_interceptor = dbapi_database._method_count_interceptor
928928
method_count_interceptor.reset()
@@ -935,8 +935,8 @@ def test_consecutive_aborted_transactions(self, dbapi_database):
935935
)
936936
self._conn.commit()
937937
dbapi_database._method_abort_interceptor.reset()
938-
assert method_count_interceptor._counts[COMMIT_METHOD] == 2
939-
assert method_count_interceptor._counts[EXECUTE_STREAMING_SQL_METHOD] == 6
938+
assert method_count_interceptor._counts[COMMIT_METHOD] >= 2
939+
assert method_count_interceptor._counts[EXECUTE_STREAMING_SQL_METHOD] >= 6
940940

941941
self._cursor.execute("SELECT * FROM contacts")
942942
got_rows = self._cursor.fetchall()

tests/unit/spanner_dbapi/test_connect.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,17 @@ def test_w_credential_file_path(self, mock_client):
137137
client_info = factory.call_args_list[0][1]["client_info"]
138138
self.assertEqual(client_info.user_agent, USER_AGENT)
139139
self.assertEqual(client_info.python_version, PY_VERSION)
140+
141+
def test_with_kwargs(self, mock_client):
142+
from google.cloud.spanner_dbapi import connect
143+
from google.cloud.spanner_dbapi import Connection
144+
145+
client = mock_client.return_value
146+
instance = client.instance.return_value
147+
database = instance.database.return_value
148+
self.assertIsNotNone(database)
149+
150+
connection = connect(INSTANCE, DATABASE, ignore_transaction_warnings=True)
151+
152+
self.assertIsInstance(connection, Connection)
153+
self.assertTrue(connection._ignore_transaction_warnings)

0 commit comments

Comments
 (0)