Skip to content

fix: require source/target roles in binary relation_members validation - #91

Merged
yifanfeng97 merged 2 commits into
yifanfeng97:mainfrom
dex0shubham:fix/validator-relation-members-roles
Sep 9, 2026
Merged

yifanfeng97 merged 2 commits into
yifanfeng97:mainfrom
dex0shubham:fix/validator-relation-members-roles

Conversation

@dex0shubham

Copy link
Copy Markdown
Contributor

Problem

For binary graph templates, _check_relation_members only verifies that each relation_members dict value names a valid edge field — it accepts arbitrary keys:

for role, field_name in members.items():
    if field_name not in relation_fields:
        diags.append(Diagnostic(HE_T003, "error", ...))

But the runtime extractor (parsers/identifiers.py) reads the roles by name:

source_field = members["source"]
target_field = members["target"]

So a template like relation_members: {from: source, to: target} (whose values are valid edge fields) passes validation and then raises KeyError: 'source' at extraction time — precisely the failure the validator is meant to catch ahead of time.

Fix

In the binary-graph branch, require the relation_members dict to define both a source and a target role, emitting an HE-T003 error for each missing one.

Tests

tests/template_engine/test_validator.py: a graph template using non-standard role keys (from/to) with valid field values is now rejected with source/target diagnostics. The full validator suite — including TestPresetBootstrap, which validates every bundled preset clean — still passes (all presets already use source/target). The new test fails on the pre-fix code.

ruff check/ruff format --check on hyperextract clean.

@yifanfeng97

Copy link
Copy Markdown
Owner

Merged — thanks! 🎯

Verified locally: the runtime extractor does read members["source"]/members["target"] directly, so a template with non-standard role keys (e.g. from:/to:) passed validation but raised KeyError at extraction time. The validator now rejects this up front with a clear HE_T003 diagnostic, and the regression test covers it.

This will ship in the next release.

@yifanfeng97
yifanfeng97 merged commit d8fce60 into yifanfeng97:main Sep 9, 2026
4 checks passed
@dex0shubham
dex0shubham deleted the fix/validator-relation-members-roles branch September 18, 2026 18:10
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.

2 participants