]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
coerce elements in mapper.primary_key, process in __mapper_args__
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 4 Feb 2023 21:35:21 +0000 (16:35 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 5 Feb 2023 15:39:01 +0000 (10:39 -0500)
commit4b51e9a7eeeb219e031e7df235ae3c62f38d331b
tree58e1d238e19e36e7be55518a2ee19009b2c1d93a
parente8f5a9277e2ffc674cde99114845b866d7e10b51
coerce elements in mapper.primary_key, process in __mapper_args__

Repaired ORM Declarative mappings to allow for the
:paramref:`_orm.Mapper.primary_key` parameter to be specified within
``__mapper_args__`` when using :func:`_orm.mapped_column`. Despite this
usage being directly in the 2.0 documentation, the :class:`_orm.Mapper` was
not accepting the :func:`_orm.mapped_column` construct in this context. Ths
feature was already working for the :paramref:`_orm.Mapper.version_id_col`
and :paramref:`_orm.Mapper.polymorphic_on` parameters.

As part of this change, the ``__mapper_args__`` attribute may be specified
without using :func:`_orm.declared_attr` on a non-mapped mixin class,
including a ``"primary_key"`` entry that refers to :class:`_schema.Column`
or :func:`_orm.mapped_column` objects locally present on the mixin;
Declarative will also translate these columns into the correct ones for a
particular mapped class. This again was working already for the
:paramref:`_orm.Mapper.version_id_col` and
:paramref:`_orm.Mapper.polymorphic_on` parameters.  Additionally,
elements within ``"primary_key"`` may be indicated as string names of
existing mapped properties.

Fixes: #9240
Change-Id: Ie2000273289fa23e0af21ef9c6feb3962a8b848c
doc/build/changelog/unreleased_20/9240.rst [new file with mode: 0644]
lib/sqlalchemy/orm/decl_base.py
lib/sqlalchemy/orm/mapper.py
test/orm/declarative/test_basic.py