Skip to content

Fix: quote relation labels in Cypher to handle reserved keywords#7

Merged
sfph merged 1 commit into
outshift-open:mainfrom
sfph:fix/quote-cypher-relation-labels
May 1, 2026
Merged

Fix: quote relation labels in Cypher to handle reserved keywords#7
sfph merged 1 commit into
outshift-open:mainfrom
sfph:fix/quote-cypher-relation-labels

Conversation

@sfph
Copy link
Copy Markdown
Contributor

@sfph sfph commented May 1, 2026

Summary

  • Double-quote all dynamic relation labels in Edge.to_cypher_create() so that reserved Cypher/SQL keywords (e.g. REFERENCES, MATCH, CREATE) don't cause syntax errors in AgensGraph.
  • Updates the corresponding test assertion.

Fixes outshift-open/ioc-cognition-fabric-node-svc#7

Root Cause

Edge.to_cypher_create() interpolated self.relation directly into the Cypher query:

CREATE (a)-[r:REFERENCES {...}]->(b)

REFERENCES is a reserved keyword in AgensGraph/PostgreSQL, causing a psycopg2.errors.SyntaxError.

Fix

Wrap the relation label in double-quotes (AgensGraph's identifier quoting mechanism):

CREATE (a)-[r:"REFERENCES" {...}]->(b)

Note: backtick quoting (Neo4j-style) is not supported by AgensGraph.

Test plan

  • Verified fix produces valid Cypher for reserved keywords (REFERENCES, INITIATES_ENTRY_INTO)
  • Verified fix produces valid Cypher for normal relation types (RELATES_TO, KNOWS)
  • Verified all three direction patterns (forward, backward, undirected)
  • Updated existing unit test assertion
  • Patched running container and confirmed CFN successfully saves nodes/edges during live negotiation

Made with Cursor

AgensGraph rejects unquoted relation labels that collide with reserved
Cypher/SQL keywords (e.g. REFERENCES, MATCH, CREATE). Double-quote all
dynamic relation labels in Edge.to_cypher_create() so that any
LLM-extracted relationship name is safe.

Fixes outshift-open/ioc-cognition-fabric-node-svc#7

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: sfph <selina@cisco.com>
@sfph sfph force-pushed the fix/quote-cypher-relation-labels branch from 27accce to 893c0a7 Compare May 1, 2026 16:30
Copy link
Copy Markdown
Collaborator

@ssmails ssmails left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming it works with upsert/query

@sfph sfph merged commit e1031e2 into outshift-open:main May 1, 2026
5 checks passed
@sfph sfph deleted the fix/quote-cypher-relation-labels branch May 1, 2026 20:17
@sfph sfph mentioned this pull request May 1, 2026
sfph added a commit that referenced this pull request May 1, 2026
Bump version for PyPI release including the fix for quoting
Cypher relation labels that use reserved keywords (issue #7).

Signed-off-by: sfph <selina@cisco.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
sfph added a commit to sfph/ioc-cognition-fabric-node-svc that referenced this pull request May 1, 2026
Picks up the fix for quoting reserved Cypher keywords in relation
labels (e.g. REFERENCES) that caused SyntaxError in AgensGraph.

Ref: outshift-open/ioc-knowledge-memory#7
Signed-off-by: sfph <selina@cisco.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: sfph <selina@cisco.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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.

CFN should escape reserved Cypher keywords in relationship labels

2 participants