@@ -89,9 +89,11 @@ class Connection:
89
89
committed by other transactions since the start of the read-only transaction. Commit or rolling back
90
90
the read-only transaction is semantically the same, and only indicates that the read-only transaction
91
91
should end a that a new one should be started when the next statement is executed.
92
+
93
+ **kwargs: Initial value for connection variables.
92
94
"""
93
95
94
- def __init__ (self , instance , database = None , read_only = False ):
96
+ def __init__ (self , instance , database = None , read_only = False , ** kwargs ):
95
97
self ._instance = instance
96
98
self ._database = database
97
99
self ._ddl_statements = []
@@ -117,6 +119,7 @@ def __init__(self, instance, database=None, read_only=False):
117
119
self ._batch_dml_executor : BatchDmlExecutor = None
118
120
self ._transaction_helper = TransactionRetryHelper (self )
119
121
self ._autocommit_dml_mode : AutocommitDmlMode = AutocommitDmlMode .TRANSACTIONAL
122
+ self ._connection_variables = kwargs
120
123
121
124
@property
122
125
def spanner_client (self ):
@@ -206,6 +209,10 @@ def _client_transaction_started(self):
206
209
"""
207
210
return (not self ._autocommit ) or self ._transaction_begin_marked
208
211
212
+ @property
213
+ def _ignore_transaction_warnings (self ):
214
+ return self ._connection_variables .get ("ignore_transaction_warnings" , False )
215
+
209
216
@property
210
217
def instance (self ):
211
218
"""Instance to which this connection relates.
@@ -398,9 +405,10 @@ def commit(self):
398
405
if self .database is None :
399
406
raise ValueError ("Database needs to be passed for this operation" )
400
407
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
+ )
404
412
return
405
413
406
414
self .run_prior_DDL_statements ()
@@ -418,9 +426,10 @@ def rollback(self):
418
426
This is a no-op if there is no active client transaction.
419
427
"""
420
428
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
+ )
424
433
return
425
434
try :
426
435
if self ._spanner_transaction_started and not self ._read_only :
@@ -654,6 +663,7 @@ def connect(
654
663
user_agent = None ,
655
664
client = None ,
656
665
route_to_leader_enabled = True ,
666
+ ** kwargs ,
657
667
):
658
668
"""Creates a connection to a Google Cloud Spanner database.
659
669
@@ -696,6 +706,8 @@ def connect(
696
706
disable leader aware routing. Disabling leader aware routing would
697
707
route all requests in RW/PDML transactions to the closest region.
698
708
709
+ **kwargs: Initial value for connection variables.
710
+
699
711
700
712
:rtype: :class:`google.cloud.spanner_dbapi.connection.Connection`
701
713
:returns: Connection object associated with the given Google Cloud Spanner
0 commit comments