Skip to content

Commit bef067f

Browse files
authored
Merge branch 'v3' into black-up-line-length
2 parents 01018f4 + 0b3dc06 commit bef067f

File tree

7 files changed

+52
-13
lines changed

7 files changed

+52
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* Add function for global revert broken behaviour: ydb.global_allow_truncated_result, ydb.global_allow_split_transactions
2+
* Change argument names from deny_split_transactions to allow_split_transactions (with reverse value
3+
14
## 3.0.1b8 ##
25
* Fixed exception while create ResultSet with None table_settings
36

tests/aio/test_tx.py

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

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

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

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

tests/table/test_tx.py

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

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

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

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

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
@@ -116,13 +117,15 @@ async def alter_table(
116117
set_read_replicas_settings,
117118
)
118119

119-
def transaction(self, tx_mode=None, *, deny_split_transactions=True):
120+
def transaction(
121+
self, tx_mode=None, *, allow_split_transactions=_allow_split_transaction
122+
):
120123
return TxContext(
121124
self._driver,
122125
self._state,
123126
self,
124127
tx_mode,
125-
deny_split_transactions=deny_split_transactions,
128+
allow_split_transactions=allow_split_transactions,
126129
)
127130

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

ydb/global_settings.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import warnings
2+
3+
from . import convert
4+
from . import table
5+
6+
7+
def global_allow_truncated_result(enabled: bool = True):
8+
if enabled:
9+
warnings.warn("Global allow truncated response is deprecated behaviour.")
10+
else:
11+
warnings.warn(
12+
"Global deny truncated response is default behaviour. You don't need call the function."
13+
)
14+
15+
convert._default_allow_truncated_result = enabled
16+
17+
18+
def global_allow_split_transactions(enabled: bool):
19+
if enabled:
20+
warnings.warn("Global allow truncated response is deprecated behaviour.")
21+
else:
22+
warnings.warn(
23+
"Global deby truncated response is default behaviour. You don't need call the function."
24+
)
25+
26+
table._allow_split_transaction = enabled

ydb/table.py

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

30+
_allow_split_transaction = False
31+
3032
logger = logging.getLogger(__name__)
3133

3234
##################################################################
@@ -1153,7 +1155,9 @@ def execute_scheme(self, yql_text, settings=None):
11531155
pass
11541156

11551157
@abstractmethod
1156-
def transaction(self, tx_mode=None, deny_split_transactions=True):
1158+
def transaction(
1159+
self, tx_mode=None, allow_split_transactions=_allow_split_transaction
1160+
):
11571161
pass
11581162

11591163
@abstractmethod
@@ -1621,13 +1625,15 @@ def execute_scheme(self, yql_text, settings=None):
16211625
self._state.endpoint,
16221626
)
16231627

1624-
def transaction(self, tx_mode=None, deny_split_transactions=True):
1628+
def transaction(
1629+
self, tx_mode=None, allow_split_transactions=_allow_split_transaction
1630+
):
16251631
return TxContext(
16261632
self._driver,
16271633
self._state,
16281634
self,
16291635
tx_mode,
1630-
deny_split_transactions=deny_split_transactions,
1636+
allow_split_transactions=allow_split_transactions,
16311637
)
16321638

16331639
def has_prepared(self, query):
@@ -2131,13 +2137,13 @@ class BaseTxContext(ITxContext):
21312137
"_driver",
21322138
"session",
21332139
"_finished",
2134-
"_deny_split_transactions",
2140+
"_allow_split_transactions",
21352141
)
21362142

21372143
_COMMIT = "commit"
21382144
_ROLLBACK = "rollback"
21392145

2140-
def __init__(self, driver, session_state, session, tx_mode=None, *, deny_split_transactions=True):
2146+
def __init__(self, driver, session_state, session, tx_mode=None, *, allow_split_transactions=_allow_split_transaction):
21412147
"""
21422148
An object that provides a simple transaction context manager that allows statements execution
21432149
in a transaction. You don't have to open transaction explicitly, because context manager encapsulates
@@ -2161,7 +2167,7 @@ def __init__(self, driver, session_state, session, tx_mode=None, *, deny_split_t
21612167
self._session_state = session_state
21622168
self.session = session
21632169
self._finished = ""
2164-
self._deny_split_transactions = deny_split_transactions
2170+
self._allow_split_transactions = allow_split_transactions
21652171

21662172
def __enter__(self):
21672173
"""
@@ -2321,7 +2327,7 @@ def _check_split(self, allow=""):
23212327
Deny all operaions with transaction after commit/rollback.
23222328
Exception: double commit and double rollbacks, because it is safe
23232329
"""
2324-
if not self._deny_split_transactions:
2330+
if self._allow_split_transactions:
23252331
return
23262332

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

0 commit comments

Comments
 (0)