Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getattr not working on Namespace #104

Closed
sqlalchemy-bot opened this issue Mar 8, 2009 · 2 comments
Closed

getattr not working on Namespace #104

sqlalchemy-bot opened this issue Mar 8, 2009 · 2 comments
Labels
bug Something isn't working low priority runtime

Comments

@sqlalchemy-bot
Copy link

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."""
@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

3f87430

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working low priority runtime
Projects
None yet
Development

No branches or pull requests

1 participant