mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
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:
parent
035d8cf51b
commit
f49da71e87
@ -346,18 +346,27 @@ class Neo4jGraph(GraphStore):
|
||||
)
|
||||
|
||||
url = get_from_dict_or_env({"url": url}, "url", "NEO4J_URI")
|
||||
username = get_from_dict_or_env(
|
||||
{"username": username}, "username", "NEO4J_USERNAME"
|
||||
)
|
||||
password = get_from_dict_or_env(
|
||||
{"password": password}, "password", "NEO4J_PASSWORD"
|
||||
)
|
||||
# if username and password are "", assume Neo4j auth is disabled
|
||||
if username == "" and password == "":
|
||||
auth = None
|
||||
else:
|
||||
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": database}, "database", "NEO4J_DATABASE", "neo4j"
|
||||
)
|
||||
|
||||
self._driver = neo4j.GraphDatabase.driver(
|
||||
url, auth=(username, password), **(driver_config or {})
|
||||
url, auth=auth, **(driver_config or {})
|
||||
)
|
||||
self._database = database
|
||||
self.timeout = timeout
|
||||
|
Loading…
Reference in New Issue
Block a user