Skip to content

Commit 0d02673

Browse files
authored
Main global settings (#215) change internal deny split to positive allow split (with false by default) - for increase readable
1 parent 796175a commit 0d02673

File tree

7 files changed

+41
-14
lines changed

7 files changed

+41
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
* Flag for deny split transaction
1+
* Added functions for global change behaviour for compatible with future sdk version: ydb.global_allow_truncated_result and global_allow_split_transactions
22

33
## 2.12.3 ##
4+
* Flag for deny split transaction
45
* Add six package to requirements
56
* Fixed error while passing date parameter in execute
67

tests/aio/test_tx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def test_split_transactions_deny_split(driver, table_name):
101101
async with ydb.aio.SessionPool(driver, 1) as pool:
102102

103103
async def check_transaction(s: ydb.aio.table.Session):
104-
async with s.transaction(deny_split_transactions=True) as tx:
104+
async with s.transaction(allow_split_transactions=False) as tx:
105105
await tx.execute("INSERT INTO %s (id) VALUES (1)" % table_name)
106106
await tx.commit()
107107

@@ -122,7 +122,7 @@ async def test_split_transactions_allow_split(driver, table_name):
122122
async with ydb.aio.SessionPool(driver, 1) as pool:
123123

124124
async def check_transaction(s: ydb.aio.table.Session):
125-
async with s.transaction(deny_split_transactions=False) as tx:
125+
async with s.transaction(allow_split_transactions=True) as tx:
126126
await tx.execute("INSERT INTO %s (id) VALUES (1)" % table_name)
127127
await tx.commit()
128128

tests/table/test_tx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_split_transactions_deny_split(driver_sync, table_name):
9595
with ydb.SessionPool(driver_sync, 1) as pool:
9696

9797
def check_transaction(s: ydb.table.Session):
98-
with s.transaction(deny_split_transactions=True) as tx:
98+
with s.transaction(allow_split_transactions=False) as tx:
9999
tx.execute("INSERT INTO %s (id) VALUES (1)" % table_name)
100100
tx.commit()
101101

@@ -115,7 +115,7 @@ def test_split_transactions_allow_split(driver_sync, table_name):
115115
with ydb.SessionPool(driver_sync, 1) as pool:
116116

117117
def check_transaction(s: ydb.table.Session):
118-
with s.transaction(deny_split_transactions=False) as tx:
118+
with s.transaction(allow_split_transactions=True) as tx:
119119
tx.execute("INSERT INTO %s (id) VALUES (1)" % table_name)
120120
tx.commit()
121121

ydb/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .credentials import * # noqa
22
from .driver import * # noqa
3+
from .global_settings import * # noqa
34
from .table import * # noqa
45
from .issues import * # noqa
56
from .types import * # noqa

ydb/aio/table.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
_scan_query_request_factory,
1414
_wrap_scan_query_response,
1515
BaseTxContext,
16+
_allow_split_transaction,
1617
)
1718
from . import _utilities
1819
from ydb import _apis, _session_impl
@@ -120,13 +121,15 @@ async def alter_table(
120121
set_read_replicas_settings,
121122
)
122123

123-
def transaction(self, tx_mode=None, *, deny_split_transactions=False):
124+
def transaction(
125+
self, tx_mode=None, *, allow_split_transactions=_allow_split_transaction
126+
):
124127
return TxContext(
125128
self._driver,
126129
self._state,
127130
self,
128131
tx_mode,
129-
deny_split_transactions=deny_split_transactions,
132+
allow_split_transactions=allow_split_transactions,
130133
)
131134

132135
async def describe_table(self, path, settings=None): # pylint: disable=W0236

ydb/global_settings.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from . import convert
2+
from . import table
3+
4+
5+
def global_allow_truncated_result(enabled: bool = True):
6+
"""
7+
call global_allow_truncated_result(False) for more safe execution and compatible with future changes
8+
"""
9+
convert._default_allow_truncated_result = enabled
10+
11+
12+
def global_allow_split_transactions(enabled: bool):
13+
"""
14+
call global_allow_truncated_result(False) for more safe execution and compatible with future changes
15+
"""
16+
table._allow_split_transaction = enabled

ydb/table.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
except ImportError:
2929
interceptor = None
3030

31+
_allow_split_transaction = True
32+
3133
logger = logging.getLogger(__name__)
3234

3335
##################################################################
@@ -1182,7 +1184,9 @@ def execute_scheme(self, yql_text, settings=None):
11821184
pass
11831185

11841186
@abstractmethod
1185-
def transaction(self, tx_mode=None, deny_split_transactions=False):
1187+
def transaction(
1188+
self, tx_mode=None, allow_split_transactions=_allow_split_transaction
1189+
):
11861190
pass
11871191

11881192
@abstractmethod
@@ -1687,13 +1691,15 @@ def execute_scheme(self, yql_text, settings=None):
16871691
self._state.endpoint,
16881692
)
16891693

1690-
def transaction(self, tx_mode=None, deny_split_transactions=False):
1694+
def transaction(
1695+
self, tx_mode=None, allow_split_transactions=_allow_split_transaction
1696+
):
16911697
return TxContext(
16921698
self._driver,
16931699
self._state,
16941700
self,
16951701
tx_mode,
1696-
deny_split_transactions=deny_split_transactions,
1702+
allow_split_transactions=allow_split_transactions,
16971703
)
16981704

16991705
def has_prepared(self, query):
@@ -2212,7 +2218,7 @@ class BaseTxContext(ITxContext):
22122218
"_driver",
22132219
"session",
22142220
"_finished",
2215-
"_deny_split_transactions",
2221+
"_allow_split_transactions",
22162222
)
22172223

22182224
_COMMIT = "commit"
@@ -2225,7 +2231,7 @@ def __init__(
22252231
session,
22262232
tx_mode=None,
22272233
*,
2228-
deny_split_transactions=False
2234+
allow_split_transactions=_allow_split_transaction
22292235
):
22302236
"""
22312237
An object that provides a simple transaction context manager that allows statements execution
@@ -2250,7 +2256,7 @@ def __init__(
22502256
self._session_state = session_state
22512257
self.session = session
22522258
self._finished = ""
2253-
self._deny_split_transactions = deny_split_transactions
2259+
self._allow_split_transactions = allow_split_transactions
22542260

22552261
def __enter__(self):
22562262
"""
@@ -2410,7 +2416,7 @@ def _check_split(self, allow=""):
24102416
Deny all operaions with transaction after commit/rollback.
24112417
Exception: double commit and double rollbacks, because it is safe
24122418
"""
2413-
if not self._deny_split_transactions:
2419+
if self._allow_split_transactions:
24142420
return
24152421

24162422
if self._finished != "" and self._finished != allow:

0 commit comments

Comments
 (0)