Skip to content

getattr not working on Namespace #104

Description

@sqlalchemy-bot

Migrated issue, originally created by Anonymous

The method runtime.py:Namespace:__getattr__ raises RuntimeException when I think it should raise AttributeError.

This comes up when you try to do this in your template:

my_attr = getattr(my_namespace, my_attrname, None)

and there is no match for my_attrname. The expected behavior would be for None to be returned but instead RuntimeException does not get caught by getattr.

The use of AttributeError is mentioned here:
http://docs.python.org/reference/datamodel.html#object.__getattr__

Index: lib/mako/runtime.py
===================================================================
--- lib/mako/runtime.py (revision 441)
+++ lib/mako/runtime.py (working copy)
@@ -260,7 +260,7 @@

         if self.inherits is not None:
             return getattr(self.inherits, key)
-        raise exceptions.RuntimeException("Namespace '%s' has no member '%s'" % (self.name, key))
+        raise AttributeError("Namespace '%s' has no member '%s'" % (self.name, key))

 def supports_caller(func):
     """apply a caller_stack compatibility decorator to a plain Python function."""

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions