Fix neo4j sanitize (#16439)

Fix the sanitization bug and add an integration test
pull/16470/head
Tomaz Bratanic 8 months ago committed by GitHub
parent 5de59f9236
commit d0a8082188
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -160,7 +160,7 @@ class Neo4jGraph(GraphStore):
data = session.run(Query(text=query, timeout=self.timeout), params)
json_data = [r.data() for r in data]
if self.sanitize:
json_data = value_sanitize(json_data)
json_data = [value_sanitize(el) for el in json_data]
return json_data
except CypherSyntaxError as e:
raise ValueError(f"Generated Cypher Statement is not valid\n{e}")

@ -88,3 +88,31 @@ def test_neo4j_timeout() -> None:
e.code
== "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…
Cancel
Save