Skip to content
This repository has been archived by the owner on Nov 28, 2021. It is now read-only.

Consider replacing hasattr in data adapters #11

Open
BradMclain opened this issue Feb 25, 2013 · 2 comments
Open

Consider replacing hasattr in data adapters #11

BradMclain opened this issue Feb 25, 2013 · 2 comments
Assignees
Labels

Comments

@BradMclain
Copy link
Contributor

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:

try:
getattr(someObject, 'someProperty')
except AttributeError:
print "Doesn't exist"
else
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.

@BradMclain
Copy link
Contributor Author

@devraj devraj closed this as completed May 16, 2014
@devraj devraj reopened this May 16, 2014
@devraj
Copy link
Member

devraj commented Jun 7, 2014

try:
   getattr(persistent_object, attribute_key)
Exception, exp:
   continue

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 milestones: 2.0.x, 2.0.0 Nov 29, 2014
@devraj devraj modified the milestone: 2.0.1 Jan 18, 2015
@devraj devraj modified the milestones: 2.0.1, 2.0.2 Feb 17, 2015
@devraj devraj modified the milestones: 2.0.2, 2.0.3 Feb 25, 2015
@BradMclain BradMclain modified the milestones: 2.0.3, 2.0.4, 2.0.5 Feb 26, 2015
@BradMclain BradMclain modified the milestones: 2.0.5, 2.0.6 Mar 5, 2015
@BradMclain BradMclain modified the milestones: 2.0.6, 2.0.5, 2.0.7 Mar 5, 2015
BradMclain added a commit that referenced this issue Nov 9, 2016
BradMclain added a commit that referenced this issue Nov 9, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants