Skip to content

Fix Cypher syntax error in relationship operations #47

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mlesyk
Copy link

@mlesyk mlesyk commented Jun 3, 2025

Summary

Fixes #44
Fixes bug preventing relationship creation/deletion due to invalid Cypher syntax.
See neo4j Cypher syntax docs

Problem

The create_relations and delete_relations methods used invalid Cypher syntax $(relation.relationType) which caused Neo.ClientError.Statement.SyntaxError.

Error: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input '$': expected a node label/relationship type name, '%' or '(' (line 6, column 29 (offset: 204))
"            MERGE (from)-[r:$(relation.relationType)]->(to)"
                             ^}					 

First problem - syntax error

MERGE (from)-[r:$(relation.relationType)]->(to)

Second - two times iteration over relations

for relation in relations:
...
            self.neo4j_driver.execute_query(
                query, 
                {"relations": [relation.model_dump() for relation in relations]}

Changes

  • create_relations(): Fixed syntax + added batch processing
  • delete_relations(): Fixed syntax + added batch processing
  • ✅ Added regex validation for relationship types

Testing

  • ✅ Creation and deletion workflow tests passed, they were failing before fix (mcp-neo4j-memory\tests\test_neo4j_memory_integration.py)
  • ✅ Single and batch operations tests using Claude Desktop
  • ✅ Input validation edge cases tests using Claude Desktop

…sing

- Fix invalid $(relation.relationType) Cypher syntax
- Add batch processing for better performance
- Include input validation for security
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.

Error during dynamic creation of relationships.
1 participant