Skip to content

Bug: bundle import fails with "Create node n expects primary key name as input" - _PK_MAP missing DbTable/ExternalClass #1322

Closed

Description

@Superhu003

Bug Description

cgc bundle import fails with KuzuDB backend when the bundle contains DbTable or ExternalClass nodes:

Import failed: Failed to import bundle: Binder exception: Create node n expects primary key name as input.

Root Cause

cgc_bundle.py::_PK_MAP is missing entries for DbTable and ExternalClass, while database_kuzu.py correctly defines their primary keys as name.

database_kuzu.py schema (correct):

CREATE NODE TABLE DbTable (name STRING, ..., PRIMARY KEY (name))
CREATE NODE TABLE ExternalClass (name STRING, ..., PRIMARY KEY (name))

cgc_bundle.py::_PK_MAP (missing entries):

_PK_MAP = {
    'Repository': 'path', 'File': 'path', 'Directory': 'path',
    'Module': 'name',
    'Function': 'uid', 'Class': 'uid', 'Variable': 'uid',
    'Trait': 'uid', 'Interface': 'uid', 'Macro': 'uid',
    'Struct': 'uid', 'Enum': 'uid', 'Union': 'uid',
    'Annotation': 'uid', 'Record': 'uid', 'Property': 'uid',
    'Parameter': 'uid',
    # <- DbTable and ExternalClass are MISSING!
}

When _import_node_batch() encounters these nodes, pk_field resolves to None, falling into:

# Line 993-995 in cgc_bundle.py
else:
    query = f"CREATE (n:{label_str}) SET n = $props"
    result = session.run(query, props=properties)

This CREATE statement provides no primary key, which KuzuDB rejects.

Reproduction

  1. Index a Java project with MySQL datasource configured (generates DbTable nodes)
  2. Export bundle: cgc bundle export project.cgc --repo .
  3. Import into fresh KuzuDB: cgc bundle import project.cgc
  4. Error occurs when processing the first unlisted node type

Real-world bundle tested: gc-starter-2.3.0.5.RELEASE (Java Spring)

  • Total: 14,842 nodes, 26,312 edges
  • DbTable: 17 nodes / ExternalClass: 265 nodes
  • Affected: 282 nodes + 613 edges

Fix

_PK_MAP = {
    # ... existing entries ...
    'DbTable': 'name',
    'ExternalClass': 'name',
}

Just add two lines to cgc_bundle.py:942.

Underlying Architectural Issue

cgc_bundle.py and database_kuzu.py maintain independent PK mapping copies. DRY violation - every new node type requires manual sync across two files. Likely to cause similar bugs for DbColumn, RedisKeyPattern, ExternalFunction, etc.

Environment

  • cgc v0.5.1, Python 3.13, KuzuDB, Windows 11

Activity

  1. github-actions commented on Jun 26, 2026

    @github-actions
    Contributor

    Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

  2. aishwaryagangaraj-web commented on Jun 27, 2026

    @aishwaryagangaraj-web
    Contributor

    Hi @Superhu003,

    Thank you for the detailed bug report and root-cause analysis.

    I would like to work on this issue. I can investigate the bundle import flow, add the missing primary key mappings for DbTable and ExternalClass, verify the import/export behavior, and add tests to prevent similar regressions in the future.

    Could you please assign this issue to me?

    Thanks!

  3. Superhu003 commented on Jun 29, 2026

    @Superhu003
    Author

    @aishwaryagangaraj-web Thanks for offering to work on this! Happy to have you take it. @maintainers — please assign.

  4. moved this from Backlog tasks to In progress in CGC Progress Boardon Jul 29, 2026
  5. moved this from In progress to Done in CGC Progress Boardon Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions