Skip to content

fix(llm): keep zero ids and primary keys in load_into_graph - #416

Open
lplalbert wants to merge 2 commits into
apache:mainfrom
lplalbert:fix/load-into-graph-zero-ids
Open

lplalbert wants to merge 2 commits into
apache:mainfrom
lplalbert:fix/load-into-graph-zero-ids

Conversation

@lplalbert

Copy link
Copy Markdown

Refs #397, #166 (Tiny Task)

What

Commit2Graph.load_into_graph uses truthiness checks where absence is meant, so
legitimate zero values are silently lost. This is the same bug class as #397 —
while #398 fixes the extraction side (property_graph_extract.py), the load-side
instances below were still open:

  • a vertex whose single primary-key value is 0 is dropped with
    "Primary-key missing"; multi-key vertices log a spurious "mark empty" warning
    and have the value reset to the type default
  • a vertex with explicit id 0 falls back to the composite mapping key, and
    if mapping_id: never records the 0 → server-vid mapping, so edges with
    integer-zero endpoints are written against raw id 0

Changes

  • Treat only None as absent for primary-key values (input_properties.get(pk) is None)
    and declared ids (mapping_id is None), and record every declared id mapping
    (if mapping_id is not None).
  • The CUSTOMIZE_STRING guard still ignores empty/False custom ids on purpose
    (those fall back to server-generated ids) — unchanged.
  • Regression tests in test_commit_to_hugegraph_load_into_graph.py for all three
    instances.

Validation (actually run; offline only)

  • red→green (stash-demonstrated): 3 new tests fail on the old code — the failure
    output shows the bug directly ("Primary-key 'code' missing in vertex {'code': 0}",
    add_edge receiving raw 0 endpoints) → whole file passes after
  • SKIP_EXTERNAL_SERVICES=true uv run pytest src/tests/operators/hugegraph_op/ → 52 passed
  • ruff format --check / ruff check → clean (588 files)
  • ty check → 271 (same as current main); the only hits mentioning this file are
    2 pre-existing ones in untouched helpers
  • Real-provider verification: none (offline tests only; no local HugeGraph instance
    was exercised)

Refs #397
Refs #166

🤖 Generated with Claude Code

Commit2Graph.load_into_graph used truthiness checks where absence was
meant, silently losing legitimate zero values (same bug class as apache#397,
which apache#398 fixes on the extraction side):

- a vertex whose single primary-key value is 0 was dropped with
  'Primary-key missing'; multi-key vertices logged a spurious
  'mark empty' warning and had the value reset to the type default
- a vertex with explicit id 0 fell back to the composite mapping key,
  and 'if mapping_id:' never recorded the 0 -> server-vid mapping, so
  edges with integer-zero endpoints were written against raw id 0

Treat only None as absent for primary-key values and declared ids. The
CUSTOMIZE_STRING guard still ignores empty/False custom ids on purpose
(those fall back to server-generated ids).

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions github-actions Bot added the llm label Nov 9, 2026

@bitflicker64 bitflicker64 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Blocking: yes. Summary: The 0 id and primary-key fixes work, and the new tests fail on the base and pass here. Narrowing the check to is None also lets an empty-string primary key through, which merges distinct vertices into one.

# 2. Handle primary-keys mode vertex
for pk in primary_keys:
if not input_properties.get(pk):
if input_properties.get(pk) is None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important: a single-key vertex with "" as its primary key was skipped before and is written now, so every such vertex of a label maps to the same server id and their edges all attach to that one vertex. Treat "" as missing too (value is None or value == ""), matching primary_key_id in hugegraph_llm_sdk/graph_utils.py, and add a test for it.

An empty-string primary key or declared id carries no identity: distinct
vertices would collide on the same vid_mapping key and merge their edges.
Treat "" as absent for pk values (skip single-pk vertices, mark-empty for
composite keys) and fall back to the composite mapping for empty declared
ids, matching the extraction layer's truthy-id checks. Zero and False
stay values.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@lplalbert

Copy link
Copy Markdown
Author

Agreed — pushed (17bd04c). Root cause: is None narrowing keeps "" as an identity value,
so distinct vertices with an empty primary key or empty declared id collide on the same
vid_mapping key and merge their edges.

Fix: "" is treated as absent for identity values — single-pk vertices with "" are skipped
like missing ones, composite keys mark-empty (pre-#397 behavior), and an empty declared id
falls back to the composite mapping so edges resolve. 0 and False stay values, and the
CUSTOMIZE_STRING guard behavior is unchanged. This matches the extraction layer, which
already treats empty ids/endpoints as absent (if original_id:, if endpoint and label:).

Tests: three regressions in test_commit_to_hugegraph_load_into_graph.py (empty single pk
dropped, empty composite part marked empty, empty declared id resolves via composite keys),
red-green verified (3 failed without the fix). 55 passed in hugegraph_op; ruff clean; ty
baseline 271 held.

@bitflicker64 bitflicker64 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Blocking: no. Score: 9/10. Summary: load_into_graph keeps 0 ids and primary keys and still treats "" as absent, matching primary_key_id; the new tests fail on the base and pass here.

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Score: 8.0/10 · Confidence: medium

Blocking: no

Summary

The loader now retains zero-valued primary keys and maps zero IDs; the earlier empty-string collision is addressed. Approval is deferred until the write path is exercised against HugeGraph.

Evidence

Reviewed the loader, extraction caller, regression tests and existing review thread. Current-head LLM and quality CI passed; the author reports offline tests.

Validation notes

No independent live HugeGraph write or edge-resolution test was run; the upstream extraction path has separate pre-existing zero endpoint limitations.

@lplalbert

Copy link
Copy Markdown
Author

Acknowledged — and the deferral is fair: verification at 17bd04c is offline only.

What the offline evidence pins (regressions fail on the pre-fix tree and pass at this head, against a mocked PyHugeClient): zero-valued ids and primary keys reach the write plan; "" is treated as absent for identity values (single-pk vertices skipped, composite keys mark-empty, an empty declared id falls back to the composite mapping so referencing edges resolve); 0/False remain values; created server ids map back so edges attach to the intended vertices.

What it does not pin: the write path against a live HugeGraph server — real addVertex/addEdge behavior for these shapes, edge attachment where empty-key vertices used to collide, and actual server responses. No live instance was exercised in this PR, so I am not claiming live-write verification; I will report a live run here if and when one happens.

The upstream extraction path's zero endpoint limitations you note are separate and pre-existing — this PR owns the loader side only (refs #397/#166) and leaves extraction unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants