Skip to content

Commit 29fb4c7

Browse files
authored
API docs: result transformer must be idempotent (#895)
Add note to the docs that `Driver.execute_query`'s result_transformer_ argument must be an idempotent function as the driver might retry the underlying transaction.
1 parent d3b736a commit 29fb4c7

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

Diff for: docs/source/api.rst

+9
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ Closing a driver will immediately shut down all connections in the pool.
273273
The transformer function must **not** return the
274274
:class:`neo4j.Result` itself.
275275

276+
277+
.. warning::
278+
279+
N.B. the driver might retry the underlying transaction so the
280+
transformer might get invoked more than once (with different
281+
:class:`neo4j.Result` objects).
282+
Therefore, it needs to be idempotent (i.e., have the same
283+
effect, regardless if called once or many times).
284+
276285
Example transformer that checks that exactly one record is in the
277286
result stream, then returns the record and the result summary::
278287

Diff for: docs/source/async_api.rst

+8
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ Closing a driver will immediately shut down all connections in the pool.
255255
The transformer function must **not** return the
256256
:class:`neo4j.AsyncResult` itself.
257257

258+
.. warning::
259+
260+
N.B. the driver might retry the underlying transaction so the
261+
transformer might get invoked more than once (with different
262+
:class:`neo4j.AsyncResult` objects).
263+
Therefore, it needs to be idempotent (i.e., have the same
264+
effect, regardless if called once or many times).
265+
258266
Example transformer that checks that exactly one record is in the
259267
result stream, then returns the record and the result summary::
260268

Diff for: src/neo4j/_async/driver.py

+8
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,14 @@ async def example(driver: neo4j.AsyncDriver) -> int:
686686
The transformer function must **not** return the
687687
:class:`neo4j.AsyncResult` itself.
688688
689+
.. warning::
690+
691+
N.B. the driver might retry the underlying transaction so the
692+
transformer might get invoked more than once (with different
693+
:class:`neo4j.AsyncResult` objects).
694+
Therefore, it needs to be idempotent (i.e., have the same
695+
effect, regardless if called once or many times).
696+
689697
Example transformer that checks that exactly one record is in the
690698
result stream, then returns the record and the result summary::
691699

Diff for: src/neo4j/_sync/driver.py

+8
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,14 @@ def example(driver: neo4j.Driver) -> int:
684684
The transformer function must **not** return the
685685
:class:`neo4j.Result` itself.
686686
687+
.. warning::
688+
689+
N.B. the driver might retry the underlying transaction so the
690+
transformer might get invoked more than once (with different
691+
:class:`neo4j.Result` objects).
692+
Therefore, it needs to be idempotent (i.e., have the same
693+
effect, regardless if called once or many times).
694+
687695
Example transformer that checks that exactly one record is in the
688696
result stream, then returns the record and the result summary::
689697

0 commit comments

Comments
 (0)