Skip to content

Remove session.read/write_transaction #1184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
4 changes: 0 additions & 4 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -909,12 +909,8 @@ Session

.. automethod:: begin_transaction

.. automethod:: read_transaction

.. automethod:: execute_read

.. automethod:: write_transaction

.. automethod:: execute_write


Expand Down
4 changes: 0 additions & 4 deletions docs/source/async_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -642,12 +642,8 @@ AsyncSession

.. automethod:: begin_transaction

.. automethod:: read_transaction

.. automethod:: execute_read

.. automethod:: write_transaction

.. automethod:: execute_write


Expand Down
97 changes: 0 additions & 97 deletions src/neo4j/_async/work/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
97 changes: 0 additions & 97 deletions src/neo4j/_sync/work/session.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 4 additions & 26 deletions tests/unit/async_/work/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# limitations under the License.


from contextlib import contextmanager

import pytest

from neo4j import (
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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",
),
Expand All @@ -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",
Expand All @@ -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]
Expand Down Expand Up @@ -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",
),
Expand All @@ -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()
Expand Down
Loading