From 88defe365bfe0b104c5375132929fab3cf4144ba Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Tue, 21 Mar 2023 15:36:47 +0300 Subject: [PATCH] fix default truncated response --- ydb/_topic_common/common.py | 2 +- ydb/aio/table.py | 5 +---- ydb/global_settings.py | 10 ++++++++-- ydb/table.py | 20 +++++++++++--------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/ydb/_topic_common/common.py b/ydb/_topic_common/common.py index ab9aae5c..9e8f1326 100644 --- a/ydb/_topic_common/common.py +++ b/ydb/_topic_common/common.py @@ -30,7 +30,7 @@ def wrapper(rpc_state, response_pb, driver=None): _shared_event_loop_lock = threading.Lock() -_shared_event_loop = None # type: Optional[asyncio.AbstractEventLoop] +_shared_event_loop: Optional[asyncio.AbstractEventLoop] = None def _get_shared_event_loop() -> asyncio.AbstractEventLoop: diff --git a/ydb/aio/table.py b/ydb/aio/table.py index 92ed9812..06f8ca7c 100644 --- a/ydb/aio/table.py +++ b/ydb/aio/table.py @@ -13,7 +13,6 @@ _scan_query_request_factory, _wrap_scan_query_response, BaseTxContext, - _allow_split_transaction, ) from . import _utilities from ydb import _apis, _session_impl @@ -121,9 +120,7 @@ async def alter_table( set_read_replicas_settings, ) - def transaction( - self, tx_mode=None, *, allow_split_transactions=_allow_split_transaction - ): + def transaction(self, tx_mode=None, *, allow_split_transactions=None): return TxContext( self._driver, self._state, diff --git a/ydb/global_settings.py b/ydb/global_settings.py index f1fabcc2..8edac3f4 100644 --- a/ydb/global_settings.py +++ b/ydb/global_settings.py @@ -5,6 +5,9 @@ def global_allow_truncated_result(enabled: bool = True): + if convert._default_allow_truncated_result == enabled: + return + if enabled: warnings.warn("Global allow truncated response is deprecated behaviour.") @@ -12,7 +15,10 @@ def global_allow_truncated_result(enabled: bool = True): def global_allow_split_transactions(enabled: bool): + if table._default_allow_split_transaction == enabled: + return + if enabled: - warnings.warn("Global allow truncated response is deprecated behaviour.") + warnings.warn("Global allow split transaction is deprecated behaviour.") - table._allow_split_transaction = enabled + table._default_allow_split_transaction = enabled diff --git a/ydb/table.py b/ydb/table.py index eb3a9780..799a5426 100644 --- a/ydb/table.py +++ b/ydb/table.py @@ -27,7 +27,7 @@ except ImportError: interceptor = None -_allow_split_transaction = False +_default_allow_split_transaction = False logger = logging.getLogger(__name__) @@ -1181,9 +1181,7 @@ def execute_scheme(self, yql_text, settings=None): pass @abstractmethod - def transaction( - self, tx_mode=None, allow_split_transactions=_allow_split_transaction - ): + def transaction(self, tx_mode=None, allow_split_transactions=None): pass @abstractmethod @@ -1687,9 +1685,7 @@ def execute_scheme(self, yql_text, settings=None): self._state.endpoint, ) - def transaction( - self, tx_mode=None, allow_split_transactions=_allow_split_transaction - ): + def transaction(self, tx_mode=None, allow_split_transactions=None): return TxContext( self._driver, self._state, @@ -2226,7 +2222,7 @@ def __init__( session, tx_mode=None, *, - allow_split_transactions=_allow_split_transaction + allow_split_transactions=None ): """ An object that provides a simple transaction context manager that allows statements execution @@ -2413,7 +2409,13 @@ def _check_split(self, allow=""): Deny all operaions with transaction after commit/rollback. Exception: double commit and double rollbacks, because it is safe """ - if self._allow_split_transactions: + allow_split_transaction = ( + self._allow_split_transactions + if self._allow_split_transactions is not None + else _default_allow_split_transaction + ) + + if allow_split_transaction: return if self._finished != "" and self._finished != allow: