From 98ae637eea79a0f2526598def6f9f01da813ede1 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Thu, 24 Oct 2024 16:24:54 +0200 Subject: [PATCH] Fix bug where creation of slot defined in super-class fails + clearer error message --- framework/conformance.py | 2 +- services/od.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/framework/conformance.py b/framework/conformance.py index b236fd5..d45dc15 100644 --- a/framework/conformance.py +++ b/framework/conformance.py @@ -35,7 +35,7 @@ class Conformance: self.scd_model = UUID(state.read_value(type_model_id)) self.model = model self.type_model = type_model - self.constraint_check_subtypes = constraint_check_subtypes # for a class-level constraint, also check the constraint on the subtypes of that class? + self.constraint_check_subtypes = constraint_check_subtypes # for a class-level constraint, also check the constraint on the subtypes of that class? In other words, are constraints inherited. self.type_mapping: Dict[str, str] = {} self.model_names = { # map model elements to their names to prevent iterating too much diff --git a/services/od.py b/services/od.py index a734996..a553eac 100644 --- a/services/od.py +++ b/services/od.py @@ -69,9 +69,11 @@ class OD: def create_slot(self, attr_name: str, object_name: str, target_name: str): class_name = self.get_class_of_object(object_name) attr_link_name = self.get_attr_link_name(class_name, attr_name) + if attr_link_name == None: + raise Exception(f"Failed to get link name for attribute '{attr_name}' of object '{object_name}'") # An attribute-link is indistinguishable from an ordinary link: - slot_id = self.create_link( - get_slot_link_name(object_name, attr_name), + slot_link_name = get_slot_link_name(object_name, attr_name) + slot_id = self.create_link(slot_link_name, attr_link_name, object_name, target_name) return slot_id @@ -154,9 +156,9 @@ class OD: return assoc_name else: # look for attribute in the super-types - conf = Conformance(self.bottom.state, self.type_model, get_scd_mm(self.bottom)) + conf = Conformance(self.bottom.state, self.model, self.type_model) conf.precompute_sub_types() # only need to know about subtypes - super_types = (s for s in conf.sub_types if class_name in conf.sub_types[s]) + super_types = [s for s in conf.sub_types if class_name in conf.sub_types[s]] for s in super_types: assoc_name = f"{s}_{attr_name}" if len(self.bottom.read_outgoing_elements(self.type_model, assoc_name)) == 1: