Take the 2-minute tour ×  With SQLAlchemy, is there a way to
know beforehand whether a relation would be lazy-loaded? For
example, given a lazy parent->children relation and an instance
X of "parent", I'd like to know if "X.children" is already
loaded, without triggering the query.  share|improve this
question add comment  2 Answers  up vote 1 down vote accepted  I
think you could look at the child's __dict__ attribute
dictionary to check if the data is already there or not.
share|improve this answer It works, thanks :) –  Joril Nov 5 '08
at 9:03 add comment  Slightly neater than Haes answer (though it
effectively does the same thing) is to use hasattr(), as in:
>>> hasattr(X, 'children') share|improve this answer Nice,
thanks :) –  Joril Jan 16 '13 at 8:10 This doesn't work with
current sqlalchemy. hasattr(obj, field) is not equivalent to
field in obj.__dict__. –  Björn Lindqvist Mar 10 '13 at 13:41
I've tested in SQLAlchemy 0.8 and this does work if the object
is detached. However if it is attached then u