Skip to content

Commit

Permalink
API docs: be more explicit about access modes (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
robsdedude authored Jul 5, 2022
1 parent 0723458 commit 1becfc5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
19 changes: 12 additions & 7 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -666,16 +666,21 @@ The default access mode.

A session can be given a default access mode on construction.

This applies only in clustered environments and determines whether transactions carried out within that session should be routed to a ``read`` or ``write`` server by default.
This applies only in clustered environments and determines whether transactions
carried out within that session should be routed to a ``read`` or ``write``
server by default.

Transactions (see :ref:`managed-transactions-ref`) within a session can override the access mode passed to that session on construction.
Transactions (see :ref:`managed-transactions-ref`) within a session override the
access mode passed to that session on construction.

.. note::
The driver does not parse Cypher queries and cannot determine whether the access mode should be ``neo4j.ACCESS_WRITE`` or ``neo4j.ACCESS_READ``.
Since the access mode is not passed to the server, this can allow a ``neo4j.ACCESS_WRITE`` statement to be executed for a ``neo4j.ACCESS_READ`` call on a single instance.
Clustered environments are not susceptible to this loophole as cluster roles prevent it.
This behaviour should not be relied upon as the loophole may be closed in a future release.

The driver does not parse Cypher queries and cannot determine whether the
access mode should be ``neo4j.ACCESS_WRITE`` or ``neo4j.ACCESS_READ``.
This setting is only meant to enable the driver to perform correct routing,
*not* for enforcing access control. This means that, depending on the server
version and settings, the server or cluster might allow a write-statement to
be executed even when ``neo4j.ACCESS_READ`` is chosen. This behaviour should
not be relied upon as it can change with the server.

:Type: ``neo4j.WRITE_ACCESS``, ``neo4j.READ_ACCESS``
:Default: ``neo4j.WRITE_ACCESS``
Expand Down
10 changes: 10 additions & 0 deletions neo4j/_async/work/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ async def _run_transaction(

async def read_transaction(self, transaction_function, *args, **kwargs):
"""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`.
This transaction will automatically be committed unless an exception is thrown during query execution or by the user code.
Note, that this function perform retries and that the supplied `transaction_function` might get invoked more than once.
Expand Down Expand Up @@ -493,6 +498,11 @@ async def get_two_tx(tx):

async def write_transaction(self, transaction_function, *args, **kwargs):
"""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`.
This transaction will automatically be committed unless an exception is thrown during query execution or by the user code.
Note, that this function perform retries and that the supplied `transaction_function` might get invoked more than once.
Expand Down
10 changes: 10 additions & 0 deletions neo4j/_sync/work/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ def _run_transaction(

def read_transaction(self, transaction_function, *args, **kwargs):
"""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`.
This transaction will automatically be committed unless an exception is thrown during query execution or by the user code.
Note, that this function perform retries and that the supplied `transaction_function` might get invoked more than once.
Expand Down Expand Up @@ -493,6 +498,11 @@ def get_two_tx(tx):

def write_transaction(self, transaction_function, *args, **kwargs):
"""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`.
This transaction will automatically be committed unless an exception is thrown during query execution or by the user code.
Note, that this function perform retries and that the supplied `transaction_function` might get invoked more than once.
Expand Down

0 comments on commit 1becfc5

Please sign in to comment.