]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
add dataclasses callable and apply annotations more strictly
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 10 Feb 2023 21:06:23 +0000 (16:06 -0500)
committermike bayer <mike_mp@zzzcomputing.com>
Thu, 16 Feb 2023 00:09:14 +0000 (00:09 +0000)
commit18fd19e60d55b35408d94b892e0a2051bcb7ec88
treeaf402c777c265c841e46147ad309c17671f0e252
parent8855656626202e541bd2c95bc023e820a022322f
add dataclasses callable and apply annotations more strictly

Added new parameter ``dataclasses_callable`` to both the
:class:`_orm.MappedAsDataclass` class as well as the
:meth:`_orm.registry.mapped_as_dataclass` method which allows an
alternative callable to Python ``dataclasses.dataclass`` to be used in
order to produce dataclasses. The use case here is to drop in Pydantic's
dataclass function instead. Adjustments have been made to the mixin support
added for :ticket:`9179` in version 2.0.1 so that the ``__annotations__``
collection of the mixin is rewritten to not include the
:class:`_orm.Mapped` container, in the same way as occurs with mapped
classes, so that the Pydantic dataclasses constructor is not exposed to
unknown types.

Fixes: #9266
Change-Id: Ia0fab6f20b93a5cb853799dcf1b70a0386837c14
doc/build/changelog/unreleased_20/9266.rst [new file with mode: 0644]
doc/build/orm/dataclasses.rst
lib/sqlalchemy/orm/decl_api.py
lib/sqlalchemy/orm/decl_base.py
test/orm/declarative/test_dc_transforms.py