diff --git a/ontopy/patch.py b/ontopy/patch.py index 61c68e50c..2b744b5aa 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -29,6 +29,7 @@ def render_func(entity): # Extending ThingClass (classes) # ============================== +# Save a copy of the unpatched ThingClass.__getattr__() method. save_getattr = ThingClass.__getattr__ @@ -133,7 +134,13 @@ def _getattr(self, name): entity = self.namespace.ontology.get_by_label(name) # add annotation property to world._props for faster access later self.namespace.world._props[name] = entity - return save_getattr(self, entity.name) + + # Try first unpatched getattr method to avoid risking + # infinite recursion. + try: + return save_getattr(self, entity.name) + except AttributeError: + return getattr(self, entity.name) raise err