Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions hyperextract/utils/template_engine/parsers/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ def validate_identifiers_fields(
):
return

if not isinstance(identifiers, GraphIdentifiersSchema):
# Same diagnosis as the validator's HE-T003; without this the graph
# field checks below raise AttributeError on item_id-only identifiers.
raise ValueError(
f"{autotype} templates require identifiers.entity_id, "
"relation_id, and relation_members (not item_id)"
)

entity_fields = declared_fields.get("entities", set())
relation_fields = declared_fields.get("relations", set())

Expand Down
27 changes: 27 additions & 0 deletions tests/template_engine/test_parser_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,30 @@ def test_undeclared_time_field_still_rejected(self):
"temporal_graph",
self._declared(["name"], ["source", "target"]),
)


class TestGraphTemplateWithNaiveIdentifiers:
"""A graph-family template carrying item_id must fail with a diagnosis."""

def test_naive_identifiers_rejected_with_guidance(self):
from hyperextract.utils.template_engine.parsers.schemas import (
NaiveIdentifierSchema,
)

with pytest.raises(ValueError, match="not item_id"):
validate_identifiers_fields(
NaiveIdentifierSchema(item_id="name"),
"graph",
{"entities": {"name"}, "relations": {"source", "target"}},
)

def test_graph_identifiers_still_accepted(self):
validate_identifiers_fields(
GraphIdentifiersSchema(
entity_id="name",
relation_id="{source}|{target}",
relation_members={"source": "source", "target": "target"},
),
"graph",
{"entities": {"name"}, "relations": {"source", "target"}},
)
Loading