Skip to content

Commit 34d1789

Browse files
authored
Remove session.read/write_transaction (#1184)
Remove deprecated `session.read_transaction` and `session.write_transaction`. Instead, use `session.execute_read` and `session.execute_write` respectively.
1 parent 0e4d772 commit 34d1789

File tree

7 files changed

+10
-254
lines changed

7 files changed

+10
-254
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
6767
- Remove deprecated driver configuration option `trust`.
6868
Use `trusted_certificates` instead.
6969
- Remove the associated constants `neo4j.TRUST_ALL_CERTIFICATES` and `neo4j.TRUST_SYSTEM_CA_SIGNED_CERTIFICATES`.
70+
- Remove deprecated `session.read_transaction` and `session.write_transaction`.
71+
Instead, use `session.execute_read` and `session.execute_write` respectively.
7072
- Make undocumented classes `ResolvedAddress`, `ResolvedIPv4Address`, and `ResolvedIPv6Address` private.
7173
- Rework `PreviewWarning`.
7274
- Remove `ExperimentalWarning` and turn the few left instances of it into `PreviewWarning`.

docs/source/api.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,12 +909,8 @@ Session
909909

910910
.. automethod:: begin_transaction
911911

912-
.. automethod:: read_transaction
913-
914912
.. automethod:: execute_read
915913

916-
.. automethod:: write_transaction
917-
918914
.. automethod:: execute_write
919915

920916

docs/source/async_api.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,8 @@ AsyncSession
642642

643643
.. automethod:: begin_transaction
644644

645-
.. automethod:: read_transaction
646-
647645
.. automethod:: execute_read
648646

649-
.. automethod:: write_transaction
650-
651647
.. automethod:: execute_write
652648

653649

src/neo4j/_async/work/session.py

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@
2626
from ..._async_compat import async_sleep
2727
from ..._async_compat.util import AsyncUtil
2828
from ..._conf import SessionConfig
29-
30-
31-
if t.TYPE_CHECKING:
32-
from typing_extensions import deprecated
33-
else:
34-
from ..._warnings import deprecated
35-
3629
from ..._util import ContextBool
3730
from ..._work import Query
3831
from ...api import (
@@ -673,51 +666,6 @@ async def get_two_tx(tx):
673666
kwargs,
674667
)
675668

676-
# TODO: 6.0 - Remove this method
677-
@deprecated("read_transaction has been renamed to execute_read")
678-
@AsyncNonConcurrentMethodChecker._non_concurrent_method
679-
async def read_transaction(
680-
self,
681-
transaction_function: t.Callable[
682-
te.Concatenate[AsyncManagedTransaction, _P], t.Awaitable[_R]
683-
],
684-
*args: _P.args,
685-
**kwargs: _P.kwargs,
686-
) -> _R:
687-
"""
688-
Execute a unit of work in a managed read transaction.
689-
690-
.. note::
691-
This does not necessarily imply access control, see the session
692-
configuration option :ref:`default-access-mode-ref`.
693-
694-
:param transaction_function: a function that takes a transaction as an
695-
argument and does work with the transaction.
696-
``transaction_function(tx, *args, **kwargs)`` where ``tx`` is a
697-
:class:`.AsyncManagedTransaction`.
698-
:type transaction_function:
699-
typing.Callable[[AsyncManagedTransaction, P], typing.Awaitable[R]]
700-
:param args: additional arguments for the `transaction_function`
701-
:type args: P
702-
:param kwargs: key word arguments for the `transaction_function`
703-
:type kwargs: P
704-
705-
:returns: a result as returned by the given unit of work
706-
:rtype: R
707-
708-
:raises SessionError: if the session has been closed.
709-
710-
.. deprecated:: 5.0
711-
Method was renamed to :meth:`.execute_read`.
712-
"""
713-
return await self._run_transaction(
714-
READ_ACCESS,
715-
TelemetryAPI.TX_FUNC,
716-
transaction_function,
717-
args,
718-
kwargs,
719-
)
720-
721669
@AsyncNonConcurrentMethodChecker._non_concurrent_method
722670
async def execute_write(
723671
self,
@@ -779,51 +727,6 @@ async def create_node_tx(tx, name):
779727
kwargs,
780728
)
781729

782-
# TODO: 6.0 - Remove this method
783-
@deprecated("write_transaction has been renamed to execute_write")
784-
@AsyncNonConcurrentMethodChecker._non_concurrent_method
785-
async def write_transaction(
786-
self,
787-
transaction_function: t.Callable[
788-
te.Concatenate[AsyncManagedTransaction, _P], t.Awaitable[_R]
789-
],
790-
*args: _P.args,
791-
**kwargs: _P.kwargs,
792-
) -> _R:
793-
"""
794-
Execute a unit of work in a managed write transaction.
795-
796-
.. note::
797-
This does not necessarily imply access control, see the session
798-
configuration option :ref:`default-access-mode-ref`.
799-
800-
:param transaction_function: a function that takes a transaction as an
801-
argument and does work with the transaction.
802-
``transaction_function(tx, *args, **kwargs)`` where ``tx`` is a
803-
:class:`.AsyncManagedTransaction`.
804-
:type transaction_function:
805-
typing.Callable[[AsyncManagedTransaction, P], typing.Awaitable[R]]
806-
:param args: additional arguments for the `transaction_function`
807-
:type args: P
808-
:param kwargs: key word arguments for the `transaction_function`
809-
:type kwargs: P
810-
811-
:returns: a result as returned by the given unit of work
812-
:rtype: R
813-
814-
:raises SessionError: if the session has been closed.
815-
816-
.. deprecated:: 5.0
817-
Method was renamed to :meth:`.execute_write`.
818-
"""
819-
return await self._run_transaction(
820-
WRITE_ACCESS,
821-
TelemetryAPI.TX_FUNC,
822-
transaction_function,
823-
args,
824-
kwargs,
825-
)
826-
827730

828731
def retry_delay_generator(initial_delay, multiplier, jitter_factor):
829732
delay = initial_delay

src/neo4j/_sync/work/session.py

Lines changed: 0 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/unit/async_/work/test_session.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
# limitations under the License.
1515

1616

17-
from contextlib import contextmanager
18-
1917
import pytest
2018

2119
from neo4j import (
@@ -45,19 +43,6 @@
4543
from ...._async_compat import mark_async_test
4644

4745

48-
@contextmanager
49-
def assert_warns_tx_func_deprecation(tx_func_name):
50-
if tx_func_name.endswith("_transaction"):
51-
mode = tx_func_name.split("_")[0]
52-
with pytest.warns(
53-
DeprecationWarning,
54-
match=f"^{mode}_transaction has been renamed to execute_{mode}$",
55-
):
56-
yield
57-
else:
58-
yield
59-
60-
6146
@mark_async_test
6247
async def test_session_context_calls_close(mocker):
6348
s = AsyncSession(None, SessionConfig())
@@ -239,8 +224,6 @@ async def test_session_run_wrong_types(async_fake_pool, query, error_type):
239224
@pytest.mark.parametrize(
240225
"tx_type",
241226
(
242-
"write_transaction",
243-
"read_transaction",
244227
"execute_write",
245228
"execute_read",
246229
),
@@ -255,14 +238,13 @@ async def work(tx):
255238
assert isinstance(tx, AsyncManagedTransaction)
256239

257240
async with AsyncSession(async_fake_pool, SessionConfig()) as session:
258-
with assert_warns_tx_func_deprecation(tx_type):
259-
await getattr(session, tx_type)(work)
241+
await getattr(session, tx_type)(work)
260242
assert called
261243

262244

263245
@pytest.mark.parametrize(
264246
"tx_type",
265-
("write_transaction", "read_transaction", "execute_write", "execute_read"),
247+
("execute_write", "execute_read"),
266248
)
267249
@pytest.mark.parametrize(
268250
"decorator_kwargs",
@@ -286,8 +268,7 @@ async def work(tx):
286268
assert isinstance(tx, AsyncManagedTransaction)
287269

288270
async with AsyncSession(async_fake_pool, SessionConfig()) as session:
289-
with assert_warns_tx_func_deprecation(tx_type):
290-
await getattr(session, tx_type)(work)
271+
await getattr(session, tx_type)(work)
291272
assert called
292273
assert len(async_fake_pool.acquired_connection_mocks) == 1
293274
cx = async_fake_pool.acquired_connection_mocks[0]
@@ -637,8 +618,6 @@ async def test_session_unmanaged_transaction_api_telemetry(async_fake_pool):
637618
@pytest.mark.parametrize(
638619
"tx_type",
639620
(
640-
"write_transaction",
641-
"read_transaction",
642621
"execute_write",
643622
"execute_read",
644623
),
@@ -651,8 +630,7 @@ async def work(_):
651630
pass
652631

653632
async with AsyncSession(async_fake_pool, SessionConfig()) as session:
654-
with assert_warns_tx_func_deprecation(tx_type):
655-
await getattr(session, tx_type)(work)
633+
await getattr(session, tx_type)(work)
656634
assert len(async_fake_pool.acquired_connection_mocks) == 1
657635
connection_mock = async_fake_pool.acquired_connection_mocks[0]
658636
connection_mock.telemetry.assert_called_once()

0 commit comments

Comments
 (0)