Skip to content

Re-introduce session config options to verify_connectivity #743

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
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
8 changes: 3 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@
It now raises a `ResultConsumedError`.
- New method `Result.closed()` can be used to check for this condition if
necessary.
- `driver.verify_connectivity()`
- All keyword arguments have been deprecated (they were experimental).
They are now ignored and will be removed in a future release.
- The undocumented return value has been removed. If you need information
about the remote server, use `driver.get_server_info()` instead.
- The undocumented return value of `driver.verify_connectivity()` has been
removed. If you need information about the remote server, use
`driver.get_server_info()` instead.
- Transaction functions (a.k.a. managed transactions):
The first argument of transaction functions is now a `ManagedTransaction`
object. It behaves exactly like a regular `Transaction` object, except it
Expand Down
49 changes: 40 additions & 9 deletions neo4j/_async/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# limitations under the License.


import warnings

from .._async_compat.util import AsyncUtil
from .._conf import (
TrustAll,
Expand All @@ -36,6 +38,8 @@
from ..meta import (
deprecation_warn,
experimental,
experimental_warn,
ExperimentalWarning,
unclosed_resource_warn,
)

Expand Down Expand Up @@ -310,22 +314,34 @@ async def verify_connectivity(self, **config):
Even if this method raises an exception, the driver still needs to
be closed via :meth:`close` to free up all resources.

:param config: accepts the same configuration key-word arguments as
:meth:`session`.

.. warning::
All configuration key-word arguments are experimental.
They might be changed or removed in any future version without
prior notice.

:raises DriverError: if the driver cannot connect to the remote.
Use the exception to further understand the cause of the
connectivity problem.

.. versionchanged:: 5.0 the config parameters will be removed in
version 6 0. It has no effect starting with version 5.0.
.. versionchanged:: 5.0
The undocumented return value has been removed.
If you need information about the remote server, use
:meth:`get_server_info` instead.
"""
if config:
deprecation_warn(
"verify_connectivity() will not accept any configuration "
"parameters starting with version 6.0."
experimental_warn(
"All configuration key-word arguments to "
"verify_connectivity() are experimental. They might be "
"changed or removed in any future version without prior "
"notice."
)
async with self.session(**config) as session:
await session._get_server_info()

await self.get_server_info()

async def get_server_info(self):
async def get_server_info(self, **config):
"""Get information about the connected Neo4j server.

Try to establish a working read connection to the remote server or a
Expand All @@ -339,6 +355,14 @@ async def get_server_info(self):
Even if this method raises an exception, the driver still needs to
be closed via :meth:`close` to free up all resources.

:param config: accepts the same configuration key-word arguments as
:meth:`session`.

.. warning::
All configuration key-word arguments are experimental.
They might be changed or removed in any future version without
prior notice.

:rtype: ServerInfo

:raises DriverError: if the driver cannot connect to the remote.
Expand All @@ -347,7 +371,14 @@ async def get_server_info(self):

.. versionadded:: 5.0
"""
async with self.session() as session:
if config:
experimental_warn(
"All configuration key-word arguments to "
"verify_connectivity() are experimental. They might be "
"changed or removed in any future version without prior "
"notice."
)
async with self.session(**config) as session:
return await session._get_server_info()

@experimental("Feature support query, based on Bolt protocol version and Neo4j server version will change in the future.")
Expand Down
49 changes: 40 additions & 9 deletions neo4j/_sync/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# limitations under the License.


import warnings

from .._async_compat.util import Util
from .._conf import (
TrustAll,
Expand All @@ -36,6 +38,8 @@
from ..meta import (
deprecation_warn,
experimental,
experimental_warn,
ExperimentalWarning,
unclosed_resource_warn,
)

Expand Down Expand Up @@ -310,22 +314,34 @@ def verify_connectivity(self, **config):
Even if this method raises an exception, the driver still needs to
be closed via :meth:`close` to free up all resources.

:param config: accepts the same configuration key-word arguments as
:meth:`session`.

.. warning::
All configuration key-word arguments are experimental.
They might be changed or removed in any future version without
prior notice.

:raises DriverError: if the driver cannot connect to the remote.
Use the exception to further understand the cause of the
connectivity problem.

.. versionchanged:: 5.0 the config parameters will be removed in
version 6 0. It has no effect starting with version 5.0.
.. versionchanged:: 5.0
The undocumented return value has been removed.
If you need information about the remote server, use
:meth:`get_server_info` instead.
"""
if config:
deprecation_warn(
"verify_connectivity() will not accept any configuration "
"parameters starting with version 6.0."
experimental_warn(
"All configuration key-word arguments to "
"verify_connectivity() are experimental. They might be "
"changed or removed in any future version without prior "
"notice."
)
with self.session(**config) as session:
session._get_server_info()

self.get_server_info()

def get_server_info(self):
def get_server_info(self, **config):
"""Get information about the connected Neo4j server.

Try to establish a working read connection to the remote server or a
Expand All @@ -339,6 +355,14 @@ def get_server_info(self):
Even if this method raises an exception, the driver still needs to
be closed via :meth:`close` to free up all resources.

:param config: accepts the same configuration key-word arguments as
:meth:`session`.

.. warning::
All configuration key-word arguments are experimental.
They might be changed or removed in any future version without
prior notice.

:rtype: ServerInfo

:raises DriverError: if the driver cannot connect to the remote.
Expand All @@ -347,7 +371,14 @@ def get_server_info(self):

.. versionadded:: 5.0
"""
with self.session() as session:
if config:
experimental_warn(
"All configuration key-word arguments to "
"verify_connectivity() are experimental. They might be "
"changed or removed in any future version without prior "
"notice."
)
with self.session(**config) as session:
return session._get_server_info()

@experimental("Feature support query, based on Bolt protocol version and Neo4j server version will change in the future.")
Expand Down
10 changes: 6 additions & 4 deletions neo4j/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class ExperimentalWarning(Warning):
"""


def experimental_warn(message, stack_level=2):
warn(message, category=ExperimentalWarning, stacklevel=stack_level)


def experimental(message):
""" Decorator for tagging experimental functions and methods.

Expand All @@ -92,16 +96,14 @@ def decorator(f):
if asyncio.iscoroutinefunction(f):
@wraps(f)
async def inner(*args, **kwargs):
from warnings import warn
warn(message, category=ExperimentalWarning, stacklevel=2)
experimental_warn(message, stack_level=3)
return await f(*args, **kwargs)

return inner
else:
@wraps(f)
def inner(*args, **kwargs):
from warnings import warn
warn(message, category=ExperimentalWarning, stacklevel=2)
experimental_warn(message, stack_level=3)
return f(*args, **kwargs)

return inner
Expand Down
35 changes: 30 additions & 5 deletions tests/unit/async_/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
AsyncBoltDriver,
AsyncGraphDatabase,
AsyncNeo4jDriver,
ExperimentalWarning,
TRUST_ALL_CERTIFICATES,
TRUST_SYSTEM_CA_SIGNED_CERTIFICATES,
TrustAll,
Expand Down Expand Up @@ -224,18 +225,42 @@ async def test_verify_connectivity(uri, mocker):
"neo4j://127.0.0.1:9000",
))
@pytest.mark.parametrize("kwargs", (
{"access_mode": WRITE_ACCESS},
{"access_mode": READ_ACCESS},
{"default_access_mode": WRITE_ACCESS},
{"default_access_mode": READ_ACCESS},
{"fetch_size": 69},
))
@mark_async_test
async def test_verify_connectivity_parameters_are_deprecated(uri, kwargs,
mocker):
async def test_verify_connectivity_parameters_are_experimental(
uri, kwargs, mocker
):
driver = AsyncGraphDatabase.driver(uri)
mocker.patch.object(driver, "_pool", autospec=True)

try:
with pytest.warns(DeprecationWarning, match="configuration"):
with pytest.warns(ExperimentalWarning, match="configuration"):
await driver.verify_connectivity(**kwargs)
finally:
await driver.close()


@pytest.mark.parametrize("uri", (
"bolt://127.0.0.1:9000",
"neo4j://127.0.0.1:9000",
))
@pytest.mark.parametrize("kwargs", (
{"default_access_mode": WRITE_ACCESS},
{"default_access_mode": READ_ACCESS},
{"fetch_size": 69},
))
@mark_async_test
async def test_get_server_info_parameters_are_experimental(
uri, kwargs, mocker
):
driver = AsyncGraphDatabase.driver(uri)
mocker.patch.object(driver, "_pool", autospec=True)

try:
with pytest.warns(ExperimentalWarning, match="configuration"):
await driver.get_server_info(**kwargs)
finally:
await driver.close()
35 changes: 30 additions & 5 deletions tests/unit/sync/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from neo4j import (
BoltDriver,
ExperimentalWarning,
GraphDatabase,
Neo4jDriver,
TRUST_ALL_CERTIFICATES,
Expand Down Expand Up @@ -224,18 +225,42 @@ def test_verify_connectivity(uri, mocker):
"neo4j://127.0.0.1:9000",
))
@pytest.mark.parametrize("kwargs", (
{"access_mode": WRITE_ACCESS},
{"access_mode": READ_ACCESS},
{"default_access_mode": WRITE_ACCESS},
{"default_access_mode": READ_ACCESS},
{"fetch_size": 69},
))
@mark_sync_test
def test_verify_connectivity_parameters_are_deprecated(uri, kwargs,
mocker):
def test_verify_connectivity_parameters_are_experimental(
uri, kwargs, mocker
):
driver = GraphDatabase.driver(uri)
mocker.patch.object(driver, "_pool", autospec=True)

try:
with pytest.warns(DeprecationWarning, match="configuration"):
with pytest.warns(ExperimentalWarning, match="configuration"):
driver.verify_connectivity(**kwargs)
finally:
driver.close()


@pytest.mark.parametrize("uri", (
"bolt://127.0.0.1:9000",
"neo4j://127.0.0.1:9000",
))
@pytest.mark.parametrize("kwargs", (
{"default_access_mode": WRITE_ACCESS},
{"default_access_mode": READ_ACCESS},
{"fetch_size": 69},
))
@mark_sync_test
def test_get_server_info_parameters_are_experimental(
uri, kwargs, mocker
):
driver = GraphDatabase.driver(uri)
mocker.patch.object(driver, "_pool", autospec=True)

try:
with pytest.warns(ExperimentalWarning, match="configuration"):
driver.get_server_info(**kwargs)
finally:
driver.close()