Skip to content

Commit d9a40a9

Browse files
committed
fix: handle virtual properties explicitly in display rules utils
Virtual properties (with isVirtual flag) don't have RDF predicates, which was causing KeyError when iterating displayProperties in get_shape_order_from_display_rules and related functions.
1 parent 7a9d672 commit d9a40a9

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

heritrace/utils/display_rules_utils.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,13 @@ def get_property_order_from_rules(highest_priority_class: str, shape_uri: str =
746746

747747
ordered_properties = []
748748
for prop in rule.get("displayProperties", []):
749-
if isinstance(prop, dict) and "property" in prop:
749+
if not isinstance(prop, dict):
750+
continue
751+
if prop.get("isVirtual"):
752+
continue # Virtual properties don't have RDF predicates
753+
if "property" in prop:
750754
ordered_properties.append(prop["property"])
751-
755+
752756
return ordered_properties
753757

754758

@@ -771,11 +775,15 @@ def get_predicate_ordering_info(predicate_uri: str, highest_priority_class: str,
771775
rule = find_matching_rule(highest_priority_class, entity_shape, display_rules)
772776
if not rule:
773777
return None
774-
778+
775779
for prop in rule.get("displayProperties", []):
776-
if isinstance(prop, dict) and prop.get("property") == predicate_uri:
780+
if not isinstance(prop, dict):
781+
continue
782+
if prop.get("isVirtual"):
783+
continue # Virtual properties don't have RDF predicates or ordering
784+
if prop.get("property") == predicate_uri:
777785
return prop.get("orderedBy")
778-
786+
779787
return None
780788

781789

@@ -798,13 +806,19 @@ def get_shape_order_from_display_rules(highest_priority_class: str, entity_shape
798806
rule = find_matching_rule(highest_priority_class, entity_shape, display_rules)
799807
if not rule or "displayProperties" not in rule:
800808
return []
801-
809+
802810
for prop_config in rule["displayProperties"]:
811+
if not isinstance(prop_config, dict):
812+
continue
813+
if prop_config.get("isVirtual"):
814+
continue # Virtual properties don't have RDF predicates or display rules
815+
if "property" not in prop_config:
816+
continue # Defensive check for malformed configuration
803817
if prop_config["property"] == predicate_uri:
804818
if "displayRules" in prop_config:
805-
return [display_rule.get("shape") for display_rule in prop_config["displayRules"]
819+
return [display_rule.get("shape") for display_rule in prop_config["displayRules"]
806820
if display_rule.get("shape")]
807-
821+
808822
return []
809823

810824

0 commit comments

Comments
 (0)