Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Consider replacing hasattr in data adapters #11

BradMclain opened this Issue · 2 comments

2 participants


Currently data adapters use hasattr() to check for the existence of attributes on the persistent object, however hasattr fails if any Exception is thrown in the property/attribute.

This makes debugging difficult as it can hide errors in properties by treating them as non-existent attributes instead of throwing the correct exception.

An alternative approach would be to use something like the following, explicitly checking for AttributeError:

getattr(someObject, 'someProperty')

except AttributeError:
print "Doesn't exist"
print "Exists"

This error is also present in the SQLAlchemy data adapter where it hides any DetachedInstanceError exceptions that are thrown when trying to access out of session objects.

@devraj devraj was assigned
@devraj devraj closed this
@devraj devraj reopened this
   getattr(persistent_object, attribute_key)
Exception, exp:

does not work for platforms like AppEngine because NDB raises this exception if the property wasn't set for a particular object. This does not allow us to distinguish between a non existent properties vs not set properties.

SQLAlchemy might deal with it differently and it might be a per adapter solution

@BradMclain BradMclain modified the milestone: 2.0.x, 2.0.0
@devraj devraj modified the milestone: 2.0.1
@devraj devraj modified the milestone: 2.0.1, 2.0.2
@devraj devraj modified the milestone: 2.0.2, 2.0.3
@BradMclain BradMclain modified the milestone: 2.0.3, 2.0.4, 2.0.5
@BradMclain BradMclain modified the milestone: 2.0.5, 2.0.6, 2.0.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.