Skip to content

Instantly share code, notes, and snippets.

@shazow
Created May 28, 2010 04:36
Show Gist options
  • Save shazow/416755 to your computer and use it in GitHub Desktop.
Save shazow/416755 to your computer and use it in GitHub Desktop.
Inspect whether a path of properties is eagerloaded or not. (Hack)
# Helper methods for an SQLAlchemy declarative base class.
def _is_loaded(self, key):
return key in self.__dict__
def _is_loaded_all(self, path):
"""
Check if the given path of properties are eager-loaded.
`path` is similar to sqlalchemy.orm.eagerload_all, checking happens
by inspecting obj.__data__.
"""
current = self
for k in path.split('.'):
if not current._is_loaded(k):
return False
current = getattr(current, k)
if not current:
return False
if isinstance(current, list):
current = current[0]
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment