diff --git a/src/dbzero/bindings/python/Memo.cpp b/src/dbzero/bindings/python/Memo.cpp index 47efd88c..f5d0d6e7 100644 --- a/src/dbzero/bindings/python/Memo.cpp +++ b/src/dbzero/bindings/python/Memo.cpp @@ -685,10 +685,29 @@ namespace db0::python PyObject *tryGetAttributes(PyTypeObject *type) { - auto &decor = MemoTypeDecoration::get(type); - auto fixture = PyToolkit::getPyWorkspace().getWorkspace().getFixture(decor.getFixtureUUID(), AccessType::READ_ONLY); - auto &class_factory = fixture->get(); - return tryGetClassAttributes(*class_factory.getExistingType(type)); + auto &decor = MemoTypeDecoration::get(type); + auto &workspace = PyToolkit::getPyWorkspace().getWorkspace(); + auto fixture = workspace.getFixture(decor.getFixtureUUID(), AccessType::READ_ONLY); + auto &class_factory = fixture->get(); + // for scoped types, we raise an error if class not found + if (decor.isScoped()) { + return tryGetClassAttributes(*class_factory.getExistingType(type)); + } else { + // otherwise we check the default prefix and also scan other open prefixes + // in search for the class + auto type_ptr = class_factory.tryGetExistingType(type); + workspace.forEachFixture([&](const Fixture &existing_fixture) { + if (!type_ptr && existing_fixture != *fixture) { + auto &class_factory = existing_fixture.get(); + type_ptr = class_factory.tryGetExistingType(type); + } + return !type_ptr; + }); + if (!type_ptr) { + THROWF(db0::InputException) << "Class not found: " << PyToolkit::getTypeName(type); + } + return tryGetClassAttributes(*type_ptr); + } } PyObject *tryGetAttrAs(MemoObject *memo_obj, PyObject *attr, PyTypeObject *py_type) diff --git a/src/dbzero/bindings/python/MemoTypeDecoration.hpp b/src/dbzero/bindings/python/MemoTypeDecoration.hpp index 889d5c42..2fc7228a 100644 --- a/src/dbzero/bindings/python/MemoTypeDecoration.hpp +++ b/src/dbzero/bindings/python/MemoTypeDecoration.hpp @@ -64,7 +64,7 @@ namespace db0::python return m_type_id; } - // Check if scoped of this type is limited to a specific prefix + // Check if scope of this type is limited to a specific prefix bool isScoped() const; // NOTE: may return invalid / empty prefix name diff --git a/src/dbzero/object_model/class/Class.cpp b/src/dbzero/object_model/class/Class.cpp index c5150b80..f7a32082 100644 --- a/src/dbzero/object_model/class/Class.cpp +++ b/src/dbzero/object_model/class/Class.cpp @@ -355,7 +355,7 @@ namespace db0::object_model std::optional getNameVariant(std::optional type_id, std::optional type_name, std::optional module_name, std::optional type_fields_str, int variant_id) - { + { switch (variant_id) { case 0: { if (!type_id) {