Commits

Mike Bayer committed df522bc

some cascade tweaks

Comments (0)

Files changed (5)

 any relationships.
 - deferred column load could screw up the connection status in 
 a flush() under some circumstances, this was fixed
+- expunge() was not working with cascade, fixed.
+- potential endless loop in cascading operations fixed.
 
 0.2.5
 - fixed endless loop bug in select_by(), if the traversal hit

lib/sqlalchemy/orm/mapper.py

         for prop in self.__props.values():
             prop.register_dependencies(uowcommit, *args, **kwargs)
     
-    def cascade_iterator(self, type, object, callable_=None, recursive=None):
+    def cascade_iterator(self, type, object, recursive=None):
         if recursive is None:
             recursive=util.Set()
         for prop in self.__props.values():

lib/sqlalchemy/orm/session.py

         self.uow.expire(self, object)
 
     def expunge(self, object):
-        """removes the given object from this Session.  this will free all internal references to the object."""
-        self.uow.expunge(object)
-        self._unattach(object)
+        """remove the given object from this Session.  
+        
+        this will free all internal references to the object.  cascading will be applied according to the
+        'expunge' cascade rule."""
+        for c in [object] + list(object_mapper(object).cascade_iterator('expunge', object)):
+            self.uow.expunge(c)
+            self._unattach(c)
         
     def save(self, object, entity_name=None):
         """

lib/sqlalchemy/orm/unitofwork.py

         self.identity_map[key] = obj
 
     def refresh(self, sess, obj):
+        self._validate_obj(obj)
         sess.query(obj.__class__)._get(obj._instance_key, reload=True)
 
     def expire(self, sess, obj):
+        self._validate_obj(obj)
         def exp():
             sess.query(obj.__class__)._get(obj._instance_key, reload=True)
         attribute_manager.trigger_history(obj, exp)

lib/sqlalchemy/orm/util.py

         self.save_update = "save-update" in values or "all" in values
         self.merge = "merge" in values or "all" in values
         self.expunge = "expunge" in values or "all" in values
-        self.refresh_expire = "refresh-expire" in values or "all" in values
+        # refresh_expire not really implemented as of yet
+        #self.refresh_expire = "refresh-expire" in values or "all" in values
     def __contains__(self, item):
         return getattr(self, item.replace("-", "_"), False)