From 6028f8234549ad7bd4377a3408c4b869b05796a9 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 18 Aug 2013 15:57:06 -0400 Subject: [PATCH] Backported a change from 0.9 whereby the iteration of a hierarchy of mappers used in polymorphic inheritance loads is sorted on class name, which allows the SELECT statements generated for polymorphic queries to have deterministic rendering, which in turn helps with caching schemes that cache on the SQL string itself. [ticket:2779] --- doc/build/changelog/changelog_08.rst | 10 ++++++++++ lib/sqlalchemy/orm/mapper.py | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index d67c088eb1..3bfd817f1f 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -6,6 +6,16 @@ .. changelog:: :version: 0.8.3 + .. change:: + :tags: bug, orm + :tickets: 2779 + + Backported a change from 0.9 whereby the iteration of a hierarchy + of mappers used in polymorphic inheritance loads is sorted on class name, + which allows the SELECT statements generated for polymorphic queries + to have deterministic rendering, which in turn helps with caching + schemes that cache on the SQL string itself. + .. change:: :tags: bug, orm :tickets: 2794 diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index ff235eaf08..e5c9a05c2e 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1798,7 +1798,8 @@ class Mapper(_InspectionAttr): while stack: item = stack.popleft() descendants.append(item) - stack.extend(item._inheriting_mappers) + stack.extend(sorted(item._inheriting_mappers, + key=lambda m: m.class_.__name__)) return util.WeakSequence(descendants) def polymorphic_iterator(self): -- 2.47.3