Skip to content

Conversation

@danielaskdd
Copy link
Collaborator

@danielaskdd danielaskdd commented Nov 6, 2025

Fix node retrieval fail with special characters in IDs for Postgres AGE GraphStorage

Problem Statement

Nodes or edges with special characters (particularly double quotes) in their IDs were failing to be retrieved, causing the error.

Root Cause:
Node ID normalization was happening too early in single-node query methods (get_node, node_degree, get_edge). When a node ID like Node with "double quotes" was normalized before being passed to batch operations, it created key mismatches during result lookup, leading to:

  • ❌ Failed lookups for nodes with special characters (quotes, backslashes, etc.)
  • ❌ "Failed to read node properties" errors
  • ❌ Inconsistent behavior between direct queries and batch queries
  • ❌ Potential data integrity issues in graph operations

Solution

This PR refactors the normalization logic to ensure node IDs with special characters are correctly handled throughout the query pipeline:

Key Changes:

  1. Remove premature ID normalization: Single-node methods now pass original IDs directly to batch operations
  2. Add bidirectional lookup mapping: Batch methods maintain mapping between original and normalized IDs
    • {original_id → original_id, normalized_id → original_id}
  3. Filter results by requested nodes: Only return data for explicitly requested node IDs
  4. Improve error logging: Add workspace context for better debugging

Technical Implementation:

  • get_nodes_batch() and node_degrees_batch() now handle normalization internally
  • Results are consistently keyed by the caller's original request IDs (not normalized IDs)
  • Added defensive checks with warnings when lookup keys are missing

Example Fix:

# Before (❌ BROKEN):
node_id = 'Node with "double quotes"'
label = self._normalize_node_id(node_id)  # → 'Node with \\"double quotes\\"'
result = await self.get_nodes_batch([label])
return result[node_id]  # ❌ KeyError - looking for wrong key!

# After (✅ FIXED):
node_id = 'Node with "double quotes"'
result = await self.get_nodes_batch([node_id])  # Pass original ID
return result[node_id]  # ✅ Works - result keyed by original ID

• Remove premature ID normalization
• Add lookup mapping for node resolution
• Filter results by requested nodes only
• Improve error logging with workspace
@danielaskdd danielaskdd merged commit f6a0ea3 into HKUDS:main Nov 6, 2025
1 check passed
@danielaskdd danielaskdd deleted the fix-postgres branch November 6, 2025 13:39
@danielaskdd danielaskdd changed the title Fix node retrieval fail with pecial characters in IDs for Postgres AGE GraphStorage Fix node retrieval fail with special characters in IDs for Postgres AGE GraphStorage Nov 6, 2025
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.

1 participant