diff --git a/CHANGELOG.md b/CHANGELOG.md index f02fc29e6..5fd470009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,8 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog. - Remove deprecated driver configuration option `trust`. Use `trusted_certificates` instead. - Remove the associated constants `neo4j.TRUST_ALL_CERTIFICATES` and `neo4j.TRUST_SYSTEM_CA_SIGNED_CERTIFICATES`. +- Remove deprecated `session.read_transaction` and `session.write_transaction`. + Instead, use `session.execute_read` and `session.execute_write` respectively. - Make undocumented classes `ResolvedAddress`, `ResolvedIPv4Address`, and `ResolvedIPv6Address` private. - Rework `PreviewWarning`. - Remove `ExperimentalWarning` and turn the few left instances of it into `PreviewWarning`. diff --git a/docs/source/api.rst b/docs/source/api.rst index fa2c13bb7..dbd34e9d3 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -909,12 +909,8 @@ Session .. automethod:: begin_transaction - .. automethod:: read_transaction - .. automethod:: execute_read - .. automethod:: write_transaction - .. automethod:: execute_write diff --git a/docs/source/async_api.rst b/docs/source/async_api.rst index b3d9a3379..bf277a00a 100644 --- a/docs/source/async_api.rst +++ b/docs/source/async_api.rst @@ -642,12 +642,8 @@ AsyncSession .. automethod:: begin_transaction - .. automethod:: read_transaction - .. automethod:: execute_read - .. automethod:: write_transaction - .. automethod:: execute_write diff --git a/src/neo4j/_async/work/session.py b/src/neo4j/_async/work/session.py index 82b6a6344..20be04529 100644 --- a/src/neo4j/_async/work/session.py +++ b/src/neo4j/_async/work/session.py @@ -26,13 +26,6 @@ from ..._async_compat import async_sleep from ..._async_compat.util import AsyncUtil from ..._conf import SessionConfig - - -if t.TYPE_CHECKING: - from typing_extensions import deprecated -else: - from ..._warnings import deprecated - from ..._util import ContextBool from ..._work import Query from ...api import ( @@ -673,51 +666,6 @@ async def get_two_tx(tx): kwargs, ) - # TODO: 6.0 - Remove this method - @deprecated("read_transaction has been renamed to execute_read") - @AsyncNonConcurrentMethodChecker._non_concurrent_method - async def read_transaction( - self, - transaction_function: t.Callable[ - te.Concatenate[AsyncManagedTransaction, _P], t.Awaitable[_R] - ], - *args: _P.args, - **kwargs: _P.kwargs, - ) -> _R: - """ - Execute a unit of work in a managed read transaction. - - .. note:: - This does not necessarily imply access control, see the session - configuration option :ref:`default-access-mode-ref`. - - :param transaction_function: a function that takes a transaction as an - argument and does work with the transaction. - ``transaction_function(tx, *args, **kwargs)`` where ``tx`` is a - :class:`.AsyncManagedTransaction`. - :type transaction_function: - typing.Callable[[AsyncManagedTransaction, P], typing.Awaitable[R]] - :param args: additional arguments for the `transaction_function` - :type args: P - :param kwargs: key word arguments for the `transaction_function` - :type kwargs: P - - :returns: a result as returned by the given unit of work - :rtype: R - - :raises SessionError: if the session has been closed. - - .. deprecated:: 5.0 - Method was renamed to :meth:`.execute_read`. - """ - return await self._run_transaction( - READ_ACCESS, - TelemetryAPI.TX_FUNC, - transaction_function, - args, - kwargs, - ) - @AsyncNonConcurrentMethodChecker._non_concurrent_method async def execute_write( self, @@ -779,51 +727,6 @@ async def create_node_tx(tx, name): kwargs, ) - # TODO: 6.0 - Remove this method - @deprecated("write_transaction has been renamed to execute_write") - @AsyncNonConcurrentMethodChecker._non_concurrent_method - async def write_transaction( - self, - transaction_function: t.Callable[ - te.Concatenate[AsyncManagedTransaction, _P], t.Awaitable[_R] - ], - *args: _P.args, - **kwargs: _P.kwargs, - ) -> _R: - """ - Execute a unit of work in a managed write transaction. - - .. note:: - This does not necessarily imply access control, see the session - configuration option :ref:`default-access-mode-ref`. - - :param transaction_function: a function that takes a transaction as an - argument and does work with the transaction. - ``transaction_function(tx, *args, **kwargs)`` where ``tx`` is a - :class:`.AsyncManagedTransaction`. - :type transaction_function: - typing.Callable[[AsyncManagedTransaction, P], typing.Awaitable[R]] - :param args: additional arguments for the `transaction_function` - :type args: P - :param kwargs: key word arguments for the `transaction_function` - :type kwargs: P - - :returns: a result as returned by the given unit of work - :rtype: R - - :raises SessionError: if the session has been closed. - - .. deprecated:: 5.0 - Method was renamed to :meth:`.execute_write`. - """ - return await self._run_transaction( - WRITE_ACCESS, - TelemetryAPI.TX_FUNC, - transaction_function, - args, - kwargs, - ) - def retry_delay_generator(initial_delay, multiplier, jitter_factor): delay = initial_delay diff --git a/src/neo4j/_sync/work/session.py b/src/neo4j/_sync/work/session.py index 56c33d80e..959a8d8e7 100644 --- a/src/neo4j/_sync/work/session.py +++ b/src/neo4j/_sync/work/session.py @@ -26,13 +26,6 @@ from ..._async_compat import sleep from ..._async_compat.util import Util from ..._conf import SessionConfig - - -if t.TYPE_CHECKING: - from typing_extensions import deprecated -else: - from ..._warnings import deprecated - from ..._util import ContextBool from ..._work import Query from ...api import ( @@ -673,51 +666,6 @@ def get_two_tx(tx): kwargs, ) - # TODO: 6.0 - Remove this method - @deprecated("read_transaction has been renamed to execute_read") - @NonConcurrentMethodChecker._non_concurrent_method - def read_transaction( - self, - transaction_function: t.Callable[ - te.Concatenate[ManagedTransaction, _P], t.Union[_R] - ], - *args: _P.args, - **kwargs: _P.kwargs, - ) -> _R: - """ - Execute a unit of work in a managed read transaction. - - .. note:: - This does not necessarily imply access control, see the session - configuration option :ref:`default-access-mode-ref`. - - :param transaction_function: a function that takes a transaction as an - argument and does work with the transaction. - ``transaction_function(tx, *args, **kwargs)`` where ``tx`` is a - :class:`.ManagedTransaction`. - :type transaction_function: - typing.Callable[[ManagedTransaction, P], typing.Union[R]] - :param args: additional arguments for the `transaction_function` - :type args: P - :param kwargs: key word arguments for the `transaction_function` - :type kwargs: P - - :returns: a result as returned by the given unit of work - :rtype: R - - :raises SessionError: if the session has been closed. - - .. deprecated:: 5.0 - Method was renamed to :meth:`.execute_read`. - """ - return self._run_transaction( - READ_ACCESS, - TelemetryAPI.TX_FUNC, - transaction_function, - args, - kwargs, - ) - @NonConcurrentMethodChecker._non_concurrent_method def execute_write( self, @@ -779,51 +727,6 @@ def create_node_tx(tx, name): kwargs, ) - # TODO: 6.0 - Remove this method - @deprecated("write_transaction has been renamed to execute_write") - @NonConcurrentMethodChecker._non_concurrent_method - def write_transaction( - self, - transaction_function: t.Callable[ - te.Concatenate[ManagedTransaction, _P], t.Union[_R] - ], - *args: _P.args, - **kwargs: _P.kwargs, - ) -> _R: - """ - Execute a unit of work in a managed write transaction. - - .. note:: - This does not necessarily imply access control, see the session - configuration option :ref:`default-access-mode-ref`. - - :param transaction_function: a function that takes a transaction as an - argument and does work with the transaction. - ``transaction_function(tx, *args, **kwargs)`` where ``tx`` is a - :class:`.ManagedTransaction`. - :type transaction_function: - typing.Callable[[ManagedTransaction, P], typing.Union[R]] - :param args: additional arguments for the `transaction_function` - :type args: P - :param kwargs: key word arguments for the `transaction_function` - :type kwargs: P - - :returns: a result as returned by the given unit of work - :rtype: R - - :raises SessionError: if the session has been closed. - - .. deprecated:: 5.0 - Method was renamed to :meth:`.execute_write`. - """ - return self._run_transaction( - WRITE_ACCESS, - TelemetryAPI.TX_FUNC, - transaction_function, - args, - kwargs, - ) - def retry_delay_generator(initial_delay, multiplier, jitter_factor): delay = initial_delay diff --git a/tests/unit/async_/work/test_session.py b/tests/unit/async_/work/test_session.py index 9cc146bb7..ffcc1cf38 100644 --- a/tests/unit/async_/work/test_session.py +++ b/tests/unit/async_/work/test_session.py @@ -14,8 +14,6 @@ # limitations under the License. -from contextlib import contextmanager - import pytest from neo4j import ( @@ -45,19 +43,6 @@ from ...._async_compat import mark_async_test -@contextmanager -def assert_warns_tx_func_deprecation(tx_func_name): - if tx_func_name.endswith("_transaction"): - mode = tx_func_name.split("_")[0] - with pytest.warns( - DeprecationWarning, - match=f"^{mode}_transaction has been renamed to execute_{mode}$", - ): - yield - else: - yield - - @mark_async_test async def test_session_context_calls_close(mocker): s = AsyncSession(None, SessionConfig()) @@ -239,8 +224,6 @@ async def test_session_run_wrong_types(async_fake_pool, query, error_type): @pytest.mark.parametrize( "tx_type", ( - "write_transaction", - "read_transaction", "execute_write", "execute_read", ), @@ -255,14 +238,13 @@ async def work(tx): assert isinstance(tx, AsyncManagedTransaction) async with AsyncSession(async_fake_pool, SessionConfig()) as session: - with assert_warns_tx_func_deprecation(tx_type): - await getattr(session, tx_type)(work) + await getattr(session, tx_type)(work) assert called @pytest.mark.parametrize( "tx_type", - ("write_transaction", "read_transaction", "execute_write", "execute_read"), + ("execute_write", "execute_read"), ) @pytest.mark.parametrize( "decorator_kwargs", @@ -286,8 +268,7 @@ async def work(tx): assert isinstance(tx, AsyncManagedTransaction) async with AsyncSession(async_fake_pool, SessionConfig()) as session: - with assert_warns_tx_func_deprecation(tx_type): - await getattr(session, tx_type)(work) + await getattr(session, tx_type)(work) assert called assert len(async_fake_pool.acquired_connection_mocks) == 1 cx = async_fake_pool.acquired_connection_mocks[0] @@ -637,8 +618,6 @@ async def test_session_unmanaged_transaction_api_telemetry(async_fake_pool): @pytest.mark.parametrize( "tx_type", ( - "write_transaction", - "read_transaction", "execute_write", "execute_read", ), @@ -651,8 +630,7 @@ async def work(_): pass async with AsyncSession(async_fake_pool, SessionConfig()) as session: - with assert_warns_tx_func_deprecation(tx_type): - await getattr(session, tx_type)(work) + await getattr(session, tx_type)(work) assert len(async_fake_pool.acquired_connection_mocks) == 1 connection_mock = async_fake_pool.acquired_connection_mocks[0] connection_mock.telemetry.assert_called_once() diff --git a/tests/unit/sync/work/test_session.py b/tests/unit/sync/work/test_session.py index 79ce0b85a..b4f0654e8 100644 --- a/tests/unit/sync/work/test_session.py +++ b/tests/unit/sync/work/test_session.py @@ -14,8 +14,6 @@ # limitations under the License. -from contextlib import contextmanager - import pytest from neo4j import ( @@ -45,19 +43,6 @@ from ...._async_compat import mark_sync_test -@contextmanager -def assert_warns_tx_func_deprecation(tx_func_name): - if tx_func_name.endswith("_transaction"): - mode = tx_func_name.split("_")[0] - with pytest.warns( - DeprecationWarning, - match=f"^{mode}_transaction has been renamed to execute_{mode}$", - ): - yield - else: - yield - - @mark_sync_test def test_session_context_calls_close(mocker): s = Session(None, SessionConfig()) @@ -239,8 +224,6 @@ def test_session_run_wrong_types(fake_pool, query, error_type): @pytest.mark.parametrize( "tx_type", ( - "write_transaction", - "read_transaction", "execute_write", "execute_read", ), @@ -255,14 +238,13 @@ def work(tx): assert isinstance(tx, ManagedTransaction) with Session(fake_pool, SessionConfig()) as session: - with assert_warns_tx_func_deprecation(tx_type): - getattr(session, tx_type)(work) + getattr(session, tx_type)(work) assert called @pytest.mark.parametrize( "tx_type", - ("write_transaction", "read_transaction", "execute_write", "execute_read"), + ("execute_write", "execute_read"), ) @pytest.mark.parametrize( "decorator_kwargs", @@ -286,8 +268,7 @@ def work(tx): assert isinstance(tx, ManagedTransaction) with Session(fake_pool, SessionConfig()) as session: - with assert_warns_tx_func_deprecation(tx_type): - getattr(session, tx_type)(work) + getattr(session, tx_type)(work) assert called assert len(fake_pool.acquired_connection_mocks) == 1 cx = fake_pool.acquired_connection_mocks[0] @@ -637,8 +618,6 @@ def test_session_unmanaged_transaction_api_telemetry(fake_pool): @pytest.mark.parametrize( "tx_type", ( - "write_transaction", - "read_transaction", "execute_write", "execute_read", ), @@ -651,8 +630,7 @@ def work(_): pass with Session(fake_pool, SessionConfig()) as session: - with assert_warns_tx_func_deprecation(tx_type): - getattr(session, tx_type)(work) + getattr(session, tx_type)(work) assert len(fake_pool.acquired_connection_mocks) == 1 connection_mock = fake_pool.acquired_connection_mocks[0] connection_mock.telemetry.assert_called_once()