diff --git a/src/core/sheerka/services/SheerkaConceptManager.py b/src/core/sheerka/services/SheerkaConceptManager.py index 5e07704..13b19a5 100644 --- a/src/core/sheerka/services/SheerkaConceptManager.py +++ b/src/core/sheerka/services/SheerkaConceptManager.py @@ -441,7 +441,7 @@ class SheerkaConceptManager(BaseService): :param concept_to_look_for: :return: """ - while c.body is not NotInit: + while isinstance(c, Concept) and c.body is not NotInit: if self.sheerka.isinstance(c.body, concept_to_look_for): return c.body c = c.body diff --git a/tests/core/test_SheerkaConceptManager.py b/tests/core/test_SheerkaConceptManager.py index da9ba4a..fcf00bf 100644 --- a/tests/core/test_SheerkaConceptManager.py +++ b/tests/core/test_SheerkaConceptManager.py @@ -1403,6 +1403,25 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka): res = sheerka.smart_get_attr(table_instance, color) assert sheerka.isinstance(res, BuiltinConcepts.NOT_FOUND) + def test_i_cannot_smart_get_attr_when_attribute_does_not_exist(self): + sheerka, context, adjective, color, red, size, table = self.init_concepts("adjective", + "color", + Concept("red", body="red").auto_init(), + "size", + "table", + create_new=True) + sheerka.set_isa(context, color, adjective) + sheerka.set_isa(context, red, color) + sheerka.set_isa(context, size, adjective) + + table_instance = sheerka.new(table) + color_instance = sheerka.new(color, body=red) + adjective_instance = sheerka.new(adjective, body=color_instance) + sheerka.set_attr(table_instance, adjective, adjective_instance) + + res = sheerka.smart_get_attr(table_instance, size) + assert sheerka.isinstance(res, BuiltinConcepts.NOT_FOUND) + class TestSheerkaConceptManagerUsingFileBasedSheerka(TestUsingFileBasedSheerka): def test_i_can_add_several_concepts(self):