From da720e3d644b516d86de12bccf7c4c8c1be77390 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 15 Nov 2005 07:44:14 +0000 Subject: [PATCH] enhancements to lazyloader. now you can pickle objects with lazyload. --- lib/sqlalchemy/mapper.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/sqlalchemy/mapper.py b/lib/sqlalchemy/mapper.py index 5e677705ea..bdbbb6a69d 100644 --- a/lib/sqlalchemy/mapper.py +++ b/lib/sqlalchemy/mapper.py @@ -1039,11 +1039,14 @@ class LazyLoader(PropertyLoader): def execute(self, instance, row, identitykey, imap, isnew): if isnew: - # when new rows are processed, we re-set a lazyloader on the instance. this is because the constructors - # of an object might try to access its lazy-properties, which will result in nothing being returned - # since we havent mapped anything into the instance yet. - lazyload = self.setup_loader(instance) - objectstore.uow().register_callable(instance, self.key, lazyload, uselist=self.uselist, deleteremoved = self.private, live=self.live) + # when new rows are processed, we remove the managed attribute list from our object property, + # which has the effect of the class-level lazyloader being reset. this is because the constructors + # of an object, called upon object creation when the instance is created from a result set, + # might try to access its lazy-properties, which will result in nothing being returned. + # then the instance gets its state loaded from the row, but the lazyload was already triggered; + # thus this step, occuring only when the instance was just loaded from a row, + # insures that it will be triggered even if the constructor already triggered it. + objectstore.uow().attributes.reset_history(instance, self.key) def create_lazy_clause(table, primaryjoin, secondaryjoin, foreignkey): binds = {} -- 2.47.2