Skip to content

Commit 0611255

Browse files
committed
fix review comments
1 parent b4eeb02 commit 0611255

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

tests/query/test_query_session_pool.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
2+
import ydb
33
from ydb.query.pool import QuerySessionPool
44
from ydb.query.session import QuerySessionSync, QuerySessionStateEnum
55

@@ -20,7 +20,7 @@ def test_oneshot_ddl_query(self, pool: QuerySessionPool):
2020
pool.execute_with_retries("drop table Queen;")
2121

2222
def test_oneshot_query_raises(self, pool: QuerySessionPool):
23-
with pytest.raises(Exception):
23+
with pytest.raises(ydb.GenericError):
2424
pool.execute_with_retries("Is this the real life? Is this just fantasy?")
2525

2626
def test_retry_op_uses_created_session(self, pool: QuerySessionPool):
@@ -40,9 +40,8 @@ def callee(session: QuerySessionSync):
4040

4141
def test_retry_op_raises(self, pool: QuerySessionPool):
4242
def callee(session: QuerySessionSync):
43-
res = session.execute("Caught in a landslide, no escape from reality")
44-
for _ in res:
43+
with session.execute("Caught in a landslide, no escape from reality"):
4544
pass
4645

47-
with pytest.raises(Exception):
46+
with pytest.raises(ydb.GenericError):
4847
pool.retry_operation_sync(callee)

tests/query/test_query_transaction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ def test_tx_allow_double_rollback(self, tx: BaseTxContext):
2121
tx.rollback()
2222
tx.rollback()
2323

24+
@pytest.mark.skip(reason="Not sure should we keep this behavior or not")
2425
def test_tx_commit_raises_before_begin(self, tx: BaseTxContext):
2526
with pytest.raises(RuntimeError):
2627
tx.commit()
2728

29+
@pytest.mark.skip(reason="Not sure should we keep this behavior or not")
2830
def test_tx_rollback_raises_before_begin(self, tx: BaseTxContext):
2931
with pytest.raises(RuntimeError):
3032
tx.rollback()

ydb/query/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,5 +328,5 @@ def __enter__(self):
328328
return self
329329

330330
def __exit__(self, exc_type, exc_val, exc_tb):
331-
for _ in self.it:
331+
for _ in self:
332332
pass

ydb/query/transaction.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ def commit(self, settings=None):
246246
if self._tx_state._already_in(QueryTxStateEnum.COMMITTED):
247247
return
248248
self._ensure_prev_stream_finished()
249+
250+
if self._tx_state._state == QueryTxStateEnum.NOT_INITIALIZED:
251+
# TODO(vgvoleg): Discuss should we raise before begin or not
252+
return
253+
249254
self._tx_state._check_invalid_transition(QueryTxStateEnum.COMMITTED)
250255

251256
return self._driver(
@@ -262,6 +267,11 @@ def rollback(self, settings=None):
262267
return
263268

264269
self._ensure_prev_stream_finished()
270+
271+
if self._tx_state._state == QueryTxStateEnum.NOT_INITIALIZED:
272+
# TODO(vgvoleg): Discuss should we raise before begin or not
273+
return
274+
265275
self._tx_state._check_invalid_transition(QueryTxStateEnum.ROLLBACKED)
266276

267277
return self._driver(

0 commit comments

Comments
 (0)