]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
reconcile Mapper properties ordering against mapped Table
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 24 Oct 2022 15:29:36 +0000 (11:29 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 25 Oct 2022 18:30:54 +0000 (14:30 -0400)
commitb2473649e06c1d6d29baeffb1f6ca3d75a1baca8
tree0c83898c5ceb5b7602a12913bd870b074fecbf19
parent13766228c19954f8860de6a2401c44a32832ae3e
reconcile Mapper properties ordering against mapped Table

Changed a fundamental configuration behavior of :class:`.Mapper`, where
:class:`_schema.Column` objects that are explicitly present in the
:paramref:`_orm.Mapper.properties` dictionary, either directly or enclosed
within a mapper property object, will now be mapped within the order of how
they appear within the mapped :class:`.Table` (or other selectable) itself
(assuming they are in fact part of that table's list of columns), thereby
maintaining the same order of columns in the mapped selectable as is
instrumented on the mapped class, as well as what renders in an ORM SELECT
statement for that mapper. Previously (where "previously" means since
version 0.0.1), :class:`.Column` objects in the
:paramref:`_orm.Mapper.properties` dictionary would always be mapped first,
ahead of when the other columns in the mapped :class:`.Table` would be
mapped, causing a discrepancy in the order in which the mapper would
assign attributes to the mapped class as well as the order in which they
would render in statements.

The change most prominently takes place in the way that Declarative
assigns declared columns to the :class:`.Mapper`, specifically how
:class:`.Column` (or :func:`_orm.mapped_column`) objects are handled
when they have a DDL name that is explicitly different from the mapped
attribute name, as well as when constructs such as :func:`_orm.deferred`
etc. are used.   The new behavior will see the column ordering within
the mapped :class:`.Table` being the same order in which the attributes
are mapped onto the class, assigned within the :class:`.Mapper` itself,
and rendered in ORM statements such as SELECT statements, independent
of how the :class:`_schema.Column` was configured against the
:class:`.Mapper`.

Fixes: #8705
Change-Id: I95cc05061a97fe6b1654bab70e2f6da30f8f3bd3
16 files changed:
doc/build/changelog/unreleased_20/8705.rst [new file with mode: 0644]
doc/build/orm/queryguide/columns.rst
lib/sqlalchemy/orm/mapper.py
test/ext/declarative/test_inheritance.py
test/ext/test_hybrid.py
test/ext/test_serializer.py
test/orm/declarative/test_basic.py
test/orm/declarative/test_mixin.py
test/orm/declarative/test_typed_mapping.py
test/orm/dml/test_update_delete_where.py
test/orm/inheritance/test_basic.py
test/orm/inheritance/test_relationship.py
test/orm/test_core_compilation.py
test/orm/test_deferred.py
test/orm/test_mapper.py
test/orm/test_query.py