Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
- Change behavior of closed drivers:
- Raise `DriverError` on using the closed driver.
- Calling `driver.close()` again is now a no-op.
- No longer implicitly closing drivers and sessions in `__del__()` (finalizer/destructor).
Make sure to call `.close()` on them explicitly or use them in a `with` statement.


## Version 5.28
Expand Down
15 changes: 0 additions & 15 deletions src/neo4j/_async/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
SECURITY_TYPE_SELF_SIGNED_CERTIFICATE,
TelemetryAPI,
)
from .._async_compat.util import AsyncUtil
from .._conf import (
Config,
ConfigurationError,
Expand Down Expand Up @@ -509,23 +508,9 @@ async def __aexit__(self, exc_type, exc_value, traceback):
def __del__(
self,
_unclosed_resource_warn=unclosed_resource_warn,
_is_async_code=AsyncUtil.is_async_code,
_deprecation_warn=deprecation_warn,
):
if not self._closed:
_unclosed_resource_warn(self)
# TODO: 6.0 - remove this
if _is_async_code:
return
if not self._closed:
_deprecation_warn(
"Relying on AsyncDriver's destructor to close the session "
"is deprecated. Please make sure to close the session. "
"Use it as a context (`with` statement) or make sure to "
"call `.close()` explicitly. Future versions of the "
"driver will not close drivers automatically."
)
self.close()

def _check_state(self):
if self._closed:
Expand Down
24 changes: 3 additions & 21 deletions src/neo4j/_async/work/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
from ..._async_compat.util import AsyncUtil
from ..._auth_management import to_auth_dict
from ..._conf import WorkspaceConfig
from ..._warnings import (
deprecation_warn,
unclosed_resource_warn,
)
from ..._warnings import unclosed_resource_warn
from ...api import Bookmarks
from ...exceptions import (
ServiceUnavailable,
SessionError,
SessionExpired,
)
from .._debug import AsyncNonConcurrentMethodChecker
from ..io import (
Expand Down Expand Up @@ -74,29 +70,15 @@ def __init__(self, pool, config):
self._closed = False
super().__init__()

# Copy globals as function locals to make sure that they are available
# during Python shutdown when the Session is destroyed.
def __del__(
self,
_unclosed_resource_warn=unclosed_resource_warn,
_is_async_code=AsyncUtil.is_async_code,
_deprecation_warn=deprecation_warn,
):
if self._closed:
return
_unclosed_resource_warn(self)
# TODO: 6.0 - remove this
if _is_async_code:
return
try:
_deprecation_warn(
"Relying on AsyncSession's destructor to close the session "
"is deprecated. Please make sure to close the session. Use it "
"as a context (`with` statement) or make sure to call "
"`.close()` explicitly. Future versions of the driver will "
"not close sessions automatically."
)
self.close()
except (OSError, ServiceUnavailable, SessionExpired):
pass

async def __aenter__(self) -> AsyncWorkspace:
return self
Expand Down
15 changes: 0 additions & 15 deletions src/neo4j/_sync/driver.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 3 additions & 21 deletions src/neo4j/_sync/work/workspace.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.