@@ -89,9 +89,11 @@ class Connection:
8989 committed by other transactions since the start of the read-only transaction. Commit or rolling back
9090 the read-only transaction is semantically the same, and only indicates that the read-only transaction
9191 should end a that a new one should be started when the next statement is executed.
92+
93+ **kwargs: Initial value for connection variables.
9294 """
9395
94- def __init__ (self , instance , database = None , read_only = False ):
96+ def __init__ (self , instance , database = None , read_only = False , ** kwargs ):
9597 self ._instance = instance
9698 self ._database = database
9799 self ._ddl_statements = []
@@ -117,6 +119,7 @@ def __init__(self, instance, database=None, read_only=False):
117119 self ._batch_dml_executor : BatchDmlExecutor = None
118120 self ._transaction_helper = TransactionRetryHelper (self )
119121 self ._autocommit_dml_mode : AutocommitDmlMode = AutocommitDmlMode .TRANSACTIONAL
122+ self ._connection_variables = kwargs
120123
121124 @property
122125 def spanner_client (self ):
@@ -206,6 +209,10 @@ def _client_transaction_started(self):
206209 """
207210 return (not self ._autocommit ) or self ._transaction_begin_marked
208211
212+ @property
213+ def _ignore_transaction_warnings (self ):
214+ return self ._connection_variables .get ("ignore_transaction_warnings" , False )
215+
209216 @property
210217 def instance (self ):
211218 """Instance to which this connection relates.
@@ -398,9 +405,10 @@ def commit(self):
398405 if self .database is None :
399406 raise ValueError ("Database needs to be passed for this operation" )
400407 if not self ._client_transaction_started :
401- warnings .warn (
402- CLIENT_TRANSACTION_NOT_STARTED_WARNING , UserWarning , stacklevel = 2
403- )
408+ if not self ._ignore_transaction_warnings :
409+ warnings .warn (
410+ CLIENT_TRANSACTION_NOT_STARTED_WARNING , UserWarning , stacklevel = 2
411+ )
404412 return
405413
406414 self .run_prior_DDL_statements ()
@@ -418,9 +426,10 @@ def rollback(self):
418426 This is a no-op if there is no active client transaction.
419427 """
420428 if not self ._client_transaction_started :
421- warnings .warn (
422- CLIENT_TRANSACTION_NOT_STARTED_WARNING , UserWarning , stacklevel = 2
423- )
429+ if not self ._ignore_transaction_warnings :
430+ warnings .warn (
431+ CLIENT_TRANSACTION_NOT_STARTED_WARNING , UserWarning , stacklevel = 2
432+ )
424433 return
425434 try :
426435 if self ._spanner_transaction_started and not self ._read_only :
@@ -654,6 +663,7 @@ def connect(
654663 user_agent = None ,
655664 client = None ,
656665 route_to_leader_enabled = True ,
666+ ** kwargs ,
657667):
658668 """Creates a connection to a Google Cloud Spanner database.
659669
@@ -696,6 +706,8 @@ def connect(
696706 disable leader aware routing. Disabling leader aware routing would
697707 route all requests in RW/PDML transactions to the closest region.
698708
709+ **kwargs: Initial value for connection variables.
710+
699711
700712 :rtype: :class:`google.cloud.spanner_dbapi.connection.Connection`
701713 :returns: Connection object associated with the given Google Cloud Spanner
0 commit comments