sql, stream: raise for accessing derived attributes

Raising `AttributeError` is definitely wasn't correct here, since it
might push the code to assume it's a wrong entity type. Returning some stub value like `None` also could suggest incorrect derived attribute
value, leading to unexpected behaviour. So adding an error, so it would
propagate and code would need to be adjusted not to rely on derived
attributes, if it actually interacts with sql/stream.

`test_unit` was asserting that derived attr will return `None`, though
it was actually raising `AttributeError`.
This commit is contained in:
Andrej730
2026-09-02 18:30:41 +05:00
parent 2b0ebcee32
commit 1fa5eebf0c
5 changed files with 27 additions and 10 deletions
+7
View File
@@ -19,6 +19,7 @@
import tempfile
from pathlib import Path
import pytest
from ifcpatch.recipes import Ifc2Sql
import ifcopenshell
@@ -63,6 +64,12 @@ class TestEntity:
assert (element := ifc_sqlite.by_id(1))
assert element.Name == "My Project"
def test_getattr_derive(self):
ifc_sqlite = get_ifc_sqlite()
assert (units := ifc_sqlite.by_type("IfcSIUnit"))
with pytest.raises(RuntimeError):
units[0].Dimensions
def test_setattr(self):
ifc_sqlite = get_ifc_sqlite()
assert (element := ifc_sqlite.by_id(1))