community[patch]: change default Neo4j username/password (#25226)

**Description:**

Change the default Neo4j username/password (when not supplied as
environment variable or in code) from `None` to `""`.

Neo4j has an option to [disable
auth](https://neo4j.com/docs/operations-manual/current/configuration/configuration-settings/#config_dbms.security.auth_enabled)
which is helpful when developing. When auth is disabled, the username /
password through the `neo4j` module should be `""` (ie an empty string).

Empty strings get marked as false in
`langchain_core.utils.env.get_from_dict_or_env` -- changing this code /
behaviour would have a wide impact and is undesirable.

In order to both _allow_ access to Neo4j with auth disabled and _not_
impact `langchain_core` this patch is presented. The downside would be
that if a user forgets to set NEO4J_USERNAME or NEO4J_PASSWORD they
would see an invalid credentials error rather than missing credentials
error. This could be mitigated but would result in a less elegant patch!

**Issue:**
Fix issue where langchain cannot communicate with Neo4j if Neo4j auth is
disabled.
This commit is contained in:
Dan O'Donovan 2024-09-03 19:24:18 +01:00 committed by GitHub
parent 035d8cf51b
commit f49da71e87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -346,18 +346,27 @@ class Neo4jGraph(GraphStore):
) )
url = get_from_dict_or_env({"url": url}, "url", "NEO4J_URI") url = get_from_dict_or_env({"url": url}, "url", "NEO4J_URI")
username = get_from_dict_or_env( # if username and password are "", assume Neo4j auth is disabled
{"username": username}, "username", "NEO4J_USERNAME" if username == "" and password == "":
) auth = None
password = get_from_dict_or_env( else:
{"password": password}, "password", "NEO4J_PASSWORD" username = get_from_dict_or_env(
) {"username": username},
"username",
"NEO4J_USERNAME",
)
password = get_from_dict_or_env(
{"password": password},
"password",
"NEO4J_PASSWORD",
)
auth = (username, password)
database = get_from_dict_or_env( database = get_from_dict_or_env(
{"database": database}, "database", "NEO4J_DATABASE", "neo4j" {"database": database}, "database", "NEO4J_DATABASE", "neo4j"
) )
self._driver = neo4j.GraphDatabase.driver( self._driver = neo4j.GraphDatabase.driver(
url, auth=(username, password), **(driver_config or {}) url, auth=auth, **(driver_config or {})
) )
self._database = database self._database = database
self.timeout = timeout self.timeout = timeout