Skip to content
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

feat: add driver connection lifecycle mgmt to adhere to neo4j Driver expectations #14

Merged
merged 5 commits into from
Nov 29, 2024

Conversation

jtanningbed
Copy link
Contributor

Description

From neo4j driver impl:

 def __del__(
    self,
    _unclosed_resource_warn=unclosed_resource_warn,
    _is_async_code=Util.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 Driver'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()

We're currently relying on the driver destructor/python garbage collection. This PR adds basic context management which:

  • enables use of graph connection using with statement.
  • enables explicit close() of driver connection
  • raises RuntimeError when using closed connection

Type of Change

  • New feature

Complexity

Low

How Has This Been Tested?

  • Unit tests
  • Integration tests
  • Manual tests

Checklist

  • Unit tests updated
  • Integration tests updated
  • CHANGELOG.md updated

Copy link
Collaborator

@alexthomas93 alexthomas93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a small update to the tests needed. Thanks for your contribution!

@alexthomas93 alexthomas93 merged commit 3489bf5 into langchain-ai:main Nov 29, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants