mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 13:54:48 +00:00
Fix neo4j sanitize (#16439)
Fix the sanitization bug and add an integration test
This commit is contained in:
parent
5de59f9236
commit
d0a8082188
@ -160,7 +160,7 @@ class Neo4jGraph(GraphStore):
|
|||||||
data = session.run(Query(text=query, timeout=self.timeout), params)
|
data = session.run(Query(text=query, timeout=self.timeout), params)
|
||||||
json_data = [r.data() for r in data]
|
json_data = [r.data() for r in data]
|
||||||
if self.sanitize:
|
if self.sanitize:
|
||||||
json_data = value_sanitize(json_data)
|
json_data = [value_sanitize(el) for el in json_data]
|
||||||
return json_data
|
return json_data
|
||||||
except CypherSyntaxError as e:
|
except CypherSyntaxError as e:
|
||||||
raise ValueError(f"Generated Cypher Statement is not valid\n{e}")
|
raise ValueError(f"Generated Cypher Statement is not valid\n{e}")
|
||||||
|
@ -88,3 +88,31 @@ def test_neo4j_timeout() -> None:
|
|||||||
e.code
|
e.code
|
||||||
== "Neo.ClientError.Transaction.TransactionTimedOutClientConfiguration"
|
== "Neo.ClientError.Transaction.TransactionTimedOutClientConfiguration"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_neo4j_sanitize_values() -> None:
|
||||||
|
"""Test that neo4j uses the timeout correctly."""
|
||||||
|
url = os.environ.get("NEO4J_URI")
|
||||||
|
username = os.environ.get("NEO4J_USERNAME")
|
||||||
|
password = os.environ.get("NEO4J_PASSWORD")
|
||||||
|
assert url is not None
|
||||||
|
assert username is not None
|
||||||
|
assert password is not None
|
||||||
|
|
||||||
|
graph = Neo4jGraph(url=url, username=username, password=password, sanitize=True)
|
||||||
|
# Delete all nodes in the graph
|
||||||
|
graph.query("MATCH (n) DETACH DELETE n")
|
||||||
|
# Create two nodes and a relationship
|
||||||
|
graph.query(
|
||||||
|
"""
|
||||||
|
CREATE (la:LabelA {property_a: 'a'})
|
||||||
|
CREATE (lb:LabelB)
|
||||||
|
CREATE (lc:LabelC)
|
||||||
|
MERGE (la)-[:REL_TYPE]-> (lb)
|
||||||
|
MERGE (la)-[:REL_TYPE {rel_prop: 'abc'}]-> (lc)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
graph.refresh_schema()
|
||||||
|
|
||||||
|
output = graph.query("RETURN range(0,130,1) AS result")
|
||||||
|
assert output == [{}]
|
||||||
|
Loading…
Reference in New Issue
Block a user