From fa5522547150687c9b3cd41d28df08ab0512b5b2 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 28 Aug 2014 17:57:48 -0400 Subject: - Made a small adjustment to the mechanics of lazy loading, such that it has less chance of interfering with a joinload() in the very rare circumstance that an object points to itself; in this scenario, the object refers to itself while loading its attributes which can cause a mixup between loaders. The use case of "object points to itself" is not fully supported, but the fix also removes some overhead so for now is part of testing. fixes #3145 --- lib/sqlalchemy/orm/strategies.py | 5 ++++- lib/sqlalchemy/testing/util.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index c3edbf6e6..2d8a81f0a 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -634,7 +634,7 @@ class LazyLoader(AbstractRelationshipLoader): LoadLazyAttribute(key), key) return set_lazy_callable, None, None - else: + elif context.populate_existing or mapper.always_refresh: def reset_for_lazy_callable(state, dict_, row): # we are the primary manager for this attribute on # this class - reset its @@ -647,6 +647,9 @@ class LazyLoader(AbstractRelationshipLoader): state._reset(dict_, key) return reset_for_lazy_callable, None, None + else: + return None, None, None + class LoadLazyAttribute(object): diff --git a/lib/sqlalchemy/testing/util.py b/lib/sqlalchemy/testing/util.py index fc8390a79..7b3f721a6 100644 --- a/lib/sqlalchemy/testing/util.py +++ b/lib/sqlalchemy/testing/util.py @@ -203,5 +203,7 @@ class adict(dict): except KeyError: return dict.__getattribute__(self, key) - def get_all(self, *keys): + def __call__(self, *keys): return tuple([self[key] for key in keys]) + + get_all = __call__ -- cgit v1.2.1