@@ -65,6 +65,11 @@ def test_transaction_tag(self):
6565 from test .mockserver_tests .tags_model import Singer
6666
6767 add_singer_query_result ("SELECT singers.id, singers.name\n " + "FROM singers" )
68+ add_single_singer_query_result (
69+ "SELECT singers.id AS singers_id, singers.name AS singers_name\n "
70+ "FROM singers\n "
71+ "WHERE singers.id = @a0"
72+ )
6873 add_update_count ("INSERT INTO singers (id, name) VALUES (@a0, @a1)" , 1 )
6974 engine = create_engine (
7075 "spanner:///projects/p/instances/i/databases/d" ,
@@ -75,26 +80,32 @@ def test_transaction_tag(self):
7580 engine .execution_options (transaction_tag = "my-transaction-tag" )
7681 ) as session :
7782 # Execute a query and an insert statement in a read/write transaction.
83+ session .get (Singer , 1 , execution_options = {"request_tag" : "my-tag-1" })
7884 session .scalars (
79- select (Singer ).execution_options (request_tag = "my-tag-1 " )
85+ select (Singer ).execution_options (request_tag = "my-tag-2 " )
8086 ).all ()
87+ session .connection ().execution_options (request_tag = "insert-singer" )
8188 session .add (Singer (id = 1 , name = "Some Singer" ))
8289 session .commit ()
8390
8491 # Verify the requests that we got.
8592 requests = self .spanner_service .requests
86- eq_ (5 , len (requests ))
93+ eq_ (6 , len (requests ))
8794 is_instance_of (requests [0 ], BatchCreateSessionsRequest )
8895 is_instance_of (requests [1 ], BeginTransactionRequest )
8996 is_instance_of (requests [2 ], ExecuteSqlRequest )
9097 is_instance_of (requests [3 ], ExecuteSqlRequest )
91- is_instance_of (requests [4 ], CommitRequest )
98+ is_instance_of (requests [4 ], ExecuteSqlRequest )
99+ is_instance_of (requests [5 ], CommitRequest )
92100 for request in requests [2 :]:
93101 eq_ ("my-transaction-tag" , request .request_options .transaction_tag )
102+ eq_ ("my-tag-1" , requests [2 ].request_options .request_tag )
103+ eq_ ("my-tag-2" , requests [3 ].request_options .request_tag )
104+ eq_ ("insert-singer" , requests [4 ].request_options .request_tag )
94105
95106
96- def add_singer_query_result ( sql : str ):
97- result = result_set .ResultSet (
107+ def empty_singer_result_set ( ):
108+ return result_set .ResultSet (
98109 dict (
99110 metadata = result_set .ResultSetMetadata (
100111 dict (
@@ -124,6 +135,10 @@ def add_singer_query_result(sql: str):
124135 ),
125136 )
126137 )
138+
139+
140+ def add_singer_query_result (sql : str ):
141+ result = empty_singer_result_set ()
127142 result .rows .extend (
128143 [
129144 (
@@ -137,3 +152,16 @@ def add_singer_query_result(sql: str):
137152 ]
138153 )
139154 add_result (sql , result )
155+
156+
157+ def add_single_singer_query_result (sql : str ):
158+ result = empty_singer_result_set ()
159+ result .rows .extend (
160+ [
161+ (
162+ "1" ,
163+ "Jane Doe" ,
164+ ),
165+ ]
166+ )
167+ add_result (sql , result )
0 commit comments