From af0b13b6d919c8c9ddf3a803eef21cd1a00a36ce Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 30 Nov 2020 12:50:51 -0500 Subject: Send deterministic ordering into unit of work topological Improved the unit of work topological sorting system such that the toplogical sort is now deterministic based on the sorting of the input set, which itself is now sorted at the level of mappers, so that the same inputs of affected mappers should produce the same output every time, among mappers / tables that don't have any dependency on each other. This further reduces the chance of deadlocks as can be observed in a flush that UPDATEs among multiple, unrelated tables such that row locks are generated. topological.sort() has been made "deterministic" in all cases by using a separate list + set. Fixes: #5735 Change-Id: I073103df414dba549e46605b394f8ccae6e80d0e --- lib/sqlalchemy/orm/dependency.py | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/sqlalchemy/orm/dependency.py') diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index d4680e394..9c2c5ade3 100644 --- a/lib/sqlalchemy/orm/dependency.py +++ b/lib/sqlalchemy/orm/dependency.py @@ -43,6 +43,7 @@ class DependencyProcessor(object): else: self._passive_update_flag = attributes.PASSIVE_OFF + self.sort_key = "%s_%s" % (self.parent._sort_key, prop.key) self.key = prop.key if not self.prop.synchronize_pairs: raise sa_exc.ArgumentError( -- cgit v1.2.1