From: Mike Bayer Date: Sun, 18 Aug 2013 19:57:06 +0000 (-0400) Subject: Backported a change from 0.9 whereby the iteration of a hierarchy X-Git-Tag: rel_0_8_3~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6028f8234549ad7bd4377a3408c4b869b05796a9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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] --- 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):