@@ -49,3 +49,45 @@ async def test_credentials():
49
49
raised = True
50
50
51
51
assert raised
52
+
53
+
54
+ @pytest .mark .asyncio
55
+ async def test_tx_snapshot_ro (driver , database ):
56
+ session = await driver .table_client .session ().create ()
57
+ description = (
58
+ ydb .TableDescription ()
59
+ .with_primary_keys ("key" )
60
+ .with_columns (
61
+ ydb .Column ("key" , ydb .OptionalType (ydb .PrimitiveType .Uint64 )),
62
+ ydb .Column ("value" , ydb .OptionalType (ydb .PrimitiveType .Uint64 )),
63
+ )
64
+ )
65
+ await session .create_table (database + "/test" , description )
66
+ await session .transaction (ydb .SerializableReadWrite ()).execute (
67
+ """INSERT INTO `test` (`key`, `value`) VALUES (1, 1), (2, 2)""" ,
68
+ commit_tx = True ,
69
+ )
70
+
71
+ ro_tx = session .transaction (tx_mode = ydb .SnapshotReadOnly ())
72
+ data1 = await ro_tx .execute ("SELECT value FROM `test` WHERE key = 1" )
73
+
74
+ rw_tx = session .transaction (ydb .SerializableReadWrite ())
75
+ await rw_tx .execute ("UPDATE `test` SET value = value + 1" )
76
+ data2 = await ro_tx .execute ("SELECT value FROM `test` WHERE key = 1" )
77
+
78
+ await rw_tx .commit ()
79
+ data3 = await ro_tx .execute ("SELECT value FROM `test` WHERE key = 1" )
80
+
81
+ assert data1 [0 ].rows == data2 [0 ].rows == data3 [0 ].rows == [{"value" : 1 }]
82
+
83
+ await ro_tx .commit ()
84
+
85
+ with pytest .raises (ydb .issues .GenericError ) as exc_info :
86
+ await ro_tx .execute ("UPDATE `test` SET value = value + 1" )
87
+ assert "read only transaction" in exc_info .value .message
88
+
89
+ data = await session .transaction (tx_mode = ydb .SnapshotReadOnly ()).execute (
90
+ "SELECT value FROM `test` WHERE key = 1" ,
91
+ commit_tx = True ,
92
+ )
93
+ assert data [0 ].rows == [{"value" : 2 }]
0 commit comments