From f8d38b11e624b39bfea890b81e034a3e83cf9a96 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 15 Jan 2024 16:13:35 +0500 Subject: [PATCH] Migrator - display some error message for unhandled schemas Noticed it was resulting in error below migrating to IFC4X3 in some cases as we don't have a mapping for IFC4X3 yet. ``` if value is None and not attribute.optional(): UnboundLocalError: local variable 'value' referenced before assignment ``` --- src/ifcopenshell-python/ifcopenshell/util/schema.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index 4c97c18a78..6adafd7170 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -243,6 +243,7 @@ class Migrator: def migrate_attribute(self, attribute, element, new_file, new_element, new_element_schema): # print("Migrating attribute", element, new_element, attribute.name()) + old_file = element.wrapped_data.file if hasattr(element, attribute.name()): value = getattr(element, attribute.name()) # print("Attribute names matched", value) @@ -282,6 +283,16 @@ class Migrator: ) return # We tried our best + try: + value + except UnboundLocalError: + print( + f"Couldn't match attribute {attribute.name()} by name to migrate from {element} " + f"to {new_element} and there is no special mapping to handle migration " + f"from {old_file.schema} -> {new_file.schema}" + ) + return + # print("Continuing migration of {} to migrate from {} to {}".format(attribute.name(), element, new_element)) if value is None and not attribute.optional(): value = self.generate_default_value(attribute, new_file)