]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
modifcation to unitofwork to not maintain ordering within the rel_0_2_7
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 12 Aug 2006 22:58:49 +0000 (22:58 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 12 Aug 2006 22:58:49 +0000 (22:58 +0000)
"new" list or within the UOWTask "objects" list; instead, new objects
are tagged with an ordering identifier as they are registered as new
with the session, and the INSERT statements are then sorted within the
mapper save_obj.  the INSERT ordering has basically been pushed allthe way
to the end of the flush cycle. that way the various sorts and
organizations occuring within UOWTask (particularly the circular task
sort) dont have to worry about maintaining order (which they werent anyway)

CHANGES
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/unitofwork.py

diff --git a/CHANGES b/CHANGES
index 900f485d03ce2c15ee107b20153a63d0bf16b946..77c8f7b48880500a595fdeafcffff9ffd1772f95 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,14 @@ Aaron Spike for his excellent efforts.
 by not raising an error when redundant mappers were set up, fixed
 - added allow_null_pks option to Mapper, allows rows where some
 primary key columns are null (i.e. when mapping to outer joins etc)
+- modifcation to unitofwork to not maintain ordering within the
+"new" list or within the UOWTask "objects" list; instead, new objects
+are tagged with an ordering identifier as they are registered as new
+with the session, and the INSERT statements are then sorted within the 
+mapper save_obj.  the INSERT ordering has basically been pushed all
+the way to the end of the flush cycle. that way the various sorts and 
+organizations occuring within UOWTask (particularly the circular task 
+sort) dont have to worry about maintaining order (which they werent anyway)
 - fixed reflection of foreign keys to autoload the referenced table
 if it was not loaded already
 - [ticket:256] - pass URL query string arguments to connect() function
index d4d7479598b8f20d6201bbc0359e936707c373b3..689b3241b17f347d5a8584cd5b83a417c12187d2 100644 (file)
@@ -825,6 +825,9 @@ class Mapper(object):
 
             if len(insert):
                 statement = table.insert()
+                def comparator(a, b):
+                    return cmp(a[0]._sa_insert_order, b[0]._sa_insert_order)
+                insert.sort(comparator)
                 for rec in insert:
                     (obj, params) = rec
                     c = connection.execute(statement, params)
index f8bed564e6b31bdbc02db8725dd8edaa2ee2c410..ce2950d58a81770b9b23fd7e46edfd04599cd067 100644 (file)
@@ -84,7 +84,7 @@ class UnitOfWork(object):
         else:
             self.identity_map = weakref.WeakValueDictionary()
             
-        self.new = util.OrderedSet()
+        self.new = util.Set() #OrderedSet()
         self.dirty = util.Set()
         
         self.deleted = util.Set()
@@ -133,6 +133,10 @@ class UnitOfWork(object):
         if not hasattr(obj, '_instance_key'):
             mapper = object_mapper(obj)
             obj._instance_key = mapper.instance_key(obj)
+        try:
+            delattr(obj, '_sa_insert_order')
+        except AttributeError:
+            pass
         self.identity_map[obj._instance_key] = obj
         attribute_manager.commit(obj)
         
@@ -141,6 +145,7 @@ class UnitOfWork(object):
             raise InvalidRequestError("Object '%s' already has an identity - it cant be registered as new" % repr(obj))
         if obj not in self.new:
             self.new.add(obj)
+            obj._sa_insert_order = len(self.new)
         self.unregister_deleted(obj)
         
     def register_dirty(self, obj):
@@ -242,7 +247,6 @@ class UOWTransaction(object):
         mapper = object_mapper(obj)
         self.mappers.add(mapper)
         task = self.get_task_by_mapper(mapper)
-
         if postupdate:
             mod = task.append_postupdate(obj)
             if mod: self._mark_modified()
@@ -519,7 +523,7 @@ class UOWTask(object):
         # deleted by this UOWTask's Mapper.
         # in the case of the row-based "circular sort", the UOWTaskElement may
         # also reference further UOWTasks which are dependent on that UOWTaskElement.
-        self.objects = util.OrderedDict()
+        self.objects = {} #util.OrderedDict()
         
         # a list of UOWDependencyProcessors which are executed after saves and
         # before deletes, to synchronize data to dependent objects