diff options
Diffstat (limited to 'lib/sqlalchemy/orm/unitofwork.py')
-rw-r--r-- | lib/sqlalchemy/orm/unitofwork.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index 432e2e238..9f888f867 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -219,8 +219,21 @@ class UOWTransaction(object): print "------------------------" print self.dependencies print sort - for rec in sort: - rec.execute(self) + + if cycles: + # organize into a tree so that groups of nodes can be + # merged together, allowing better maintenance of insert + # ordering and other things + (head, children) = topological.organize_as_tree(self.dependencies, sort) + stack = [(head, children)] + + while stack: + node, children = stack.pop() + node.execute(self) + stack += children + else: + for rec in sort: + rec.execute(self) def finalize_flush_changes(self): |