From f21b34ffc13410420bf516efba7f6e0e55b3bb35 Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 6 Jun 2025 12:22:21 +0500 Subject: [PATCH] reassign_class - safe check to prevent errors like #6781 --- .../ifcopenshell/api/root/reassign_class.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/reassign_class.py b/src/ifcopenshell-python/ifcopenshell/api/root/reassign_class.py index ac4722bc3e..18ff02b199 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/reassign_class.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/reassign_class.py @@ -97,7 +97,7 @@ class Usecase: ) -> ifcopenshell.entity_instance: self.occurrence_class = occurrence_class was_type_product_before = product.is_a("IfcTypeProduct") - schema = ifcopenshell.schema_by_name(self.file.schema) + self.schema = schema = ifcopenshell.schema_by_name(self.file.schema) is_type_product_after: bool is_type_product_after = schema.declaration_by_name(ifc_class)._is("IfcTypeProduct") @@ -199,6 +199,9 @@ class Usecase: occurrence_class = next( iter(ifcopenshell.util.type.get_applicable_entities(ifc_class, self.file.schema)) ) + assert not self.schema.declaration_by_name(occurrence_class)._is( + "IfcTypeProduct" + ), f"Unexpected occurrence_class: '{occurrence_class}' / '{self.occurrence_class}'." for occurrence in ifcopenshell.util.element.get_types(element): self.reassign_class(occurrence, occurrence_class, predefined_type)