Skip to content

Commit fac52ee

Browse files
authored
Improve doc string around tx functions (#778)
`session.read_transaction` and `session.write_transaction` were slightly wrong about the tx class passed to the tx function. Furthermore, they are now more explicit about the idempotency required from tx funcs.
1 parent ba701d3 commit fac52ee

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

neo4j/_async/work/session.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,12 @@ async def read_transaction(
543543
This does not necessarily imply access control, see the session
544544
configuration option :ref:`default-access-mode-ref`.
545545
546-
This transaction will automatically be committed unless an exception is thrown during query execution or by the user code.
547-
Note, that this function perform retries and that the supplied `transaction_function` might get invoked more than once.
548-
549-
Managed transactions should not generally be explicitly committed
550-
(via ``await tx.commit()``).
546+
This transaction will automatically be committed when the function
547+
returns, unless an exception is thrown during query execution or by
548+
the user code. Note, that this function performs retries and that the
549+
supplied `transaction_function` might get invoked more than once.
550+
Therefore, it needs to be idempotent (i.e., have the same effect,
551+
regardless if called once or many times).
551552
552553
Example::
553554
@@ -582,8 +583,8 @@ async def get_two_tx(tx):
582583
:param transaction_function: a function that takes a transaction as an
583584
argument and does work with the transaction.
584585
`transaction_function(tx, *args, **kwargs)` where `tx` is a
585-
:class:`.AsyncTransaction`.
586-
:param args: arguments for the `transaction_function`
586+
:class:`.AsyncManagedTransaction`.
587+
:param args: additional arguments for the `transaction_function`
587588
:param kwargs: key word arguments for the `transaction_function`
588589
589590
:raises SessionError: if the session has been closed.
@@ -607,10 +608,12 @@ async def write_transaction(
607608
This does not necessarily imply access control, see the session
608609
configuration option :ref:`default-access-mode-ref`.
609610
610-
This transaction will automatically be committed unless an exception is thrown during query execution or by the user code.
611-
Note, that this function perform retries and that the supplied `transaction_function` might get invoked more than once.
612-
613-
Managed transactions should not generally be explicitly committed (via tx.commit()).
611+
This transaction will automatically be committed when the function
612+
returns unless, an exception is thrown during query execution or by
613+
the user code. Note, that this function performs retries and that the
614+
supplied `transaction_function` might get invoked more than once.
615+
Therefore, it needs to be idempotent (i.e., have the same effect,
616+
regardless if called once or many times).
614617
615618
Example::
616619
@@ -626,8 +629,8 @@ async def create_node_tx(tx, name):
626629
:param transaction_function: a function that takes a transaction as an
627630
argument and does work with the transaction.
628631
`transaction_function(tx, *args, **kwargs)` where `tx` is a
629-
:class:`.AsyncTransaction`.
630-
:param args: key word arguments for the `transaction_function`
632+
:class:`.AsyncManagedTransaction`.
633+
:param args: additional arguments for the `transaction_function`
631634
:param kwargs: key word arguments for the `transaction_function`
632635
633636
:raises SessionError: if the session has been closed.

neo4j/_sync/work/session.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,12 @@ def read_transaction(
543543
This does not necessarily imply access control, see the session
544544
configuration option :ref:`default-access-mode-ref`.
545545
546-
This transaction will automatically be committed unless an exception is thrown during query execution or by the user code.
547-
Note, that this function perform retries and that the supplied `transaction_function` might get invoked more than once.
548-
549-
Managed transactions should not generally be explicitly committed
550-
(via ``tx.commit()``).
546+
This transaction will automatically be committed when the function
547+
returns, unless an exception is thrown during query execution or by
548+
the user code. Note, that this function performs retries and that the
549+
supplied `transaction_function` might get invoked more than once.
550+
Therefore, it needs to be idempotent (i.e., have the same effect,
551+
regardless if called once or many times).
551552
552553
Example::
553554
@@ -582,8 +583,8 @@ def get_two_tx(tx):
582583
:param transaction_function: a function that takes a transaction as an
583584
argument and does work with the transaction.
584585
`transaction_function(tx, *args, **kwargs)` where `tx` is a
585-
:class:`.Transaction`.
586-
:param args: arguments for the `transaction_function`
586+
:class:`.ManagedTransaction`.
587+
:param args: additional arguments for the `transaction_function`
587588
:param kwargs: key word arguments for the `transaction_function`
588589
589590
:raises SessionError: if the session has been closed.
@@ -607,10 +608,12 @@ def write_transaction(
607608
This does not necessarily imply access control, see the session
608609
configuration option :ref:`default-access-mode-ref`.
609610
610-
This transaction will automatically be committed unless an exception is thrown during query execution or by the user code.
611-
Note, that this function perform retries and that the supplied `transaction_function` might get invoked more than once.
612-
613-
Managed transactions should not generally be explicitly committed (via tx.commit()).
611+
This transaction will automatically be committed when the function
612+
returns unless, an exception is thrown during query execution or by
613+
the user code. Note, that this function performs retries and that the
614+
supplied `transaction_function` might get invoked more than once.
615+
Therefore, it needs to be idempotent (i.e., have the same effect,
616+
regardless if called once or many times).
614617
615618
Example::
616619
@@ -626,8 +629,8 @@ def create_node_tx(tx, name):
626629
:param transaction_function: a function that takes a transaction as an
627630
argument and does work with the transaction.
628631
`transaction_function(tx, *args, **kwargs)` where `tx` is a
629-
:class:`.Transaction`.
630-
:param args: key word arguments for the `transaction_function`
632+
:class:`.ManagedTransaction`.
633+
:param args: additional arguments for the `transaction_function`
631634
:param kwargs: key word arguments for the `transaction_function`
632635
633636
:raises SessionError: if the session has been closed.

0 commit comments

Comments
 (0)