From: Mike Bayer Date: Sat, 12 Aug 2006 22:58:49 +0000 (+0000) Subject: modifcation to unitofwork to not maintain ordering within the X-Git-Tag: rel_0_2_7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae5e73cbc144239738d394ccbc835965bde2b39a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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 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) --- diff --git a/CHANGES b/CHANGES index 900f485d03..77c8f7b488 100644 --- 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 diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index d4d7479598..689b3241b1 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -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) diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index f8bed564e6..ce2950d58a 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -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