]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
enhancements to lazyloader. now you can pickle objects with lazyload.
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Nov 2005 07:44:14 +0000 (07:44 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Nov 2005 07:44:14 +0000 (07:44 +0000)
lib/sqlalchemy/mapper.py

index 5e677705ea704fd61e509270cfbd019724f2f352..bdbbb6a69d5d75c0e21ac6dd7765630d164688ab 100644 (file)
@@ -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 = {}