]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Support default_factory=list for write only / dynamic relationships
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 5 Aug 2026 15:25:19 +0000 (11:25 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 5 Aug 2026 20:37:08 +0000 (16:37 -0400)
commitf2ed6422b34a4f738f7178706019ebdbec1e950d
tree25472eb48526765d96fcd7f19b7e063490239d91
parent2e881c11262e6a2e808644cc6838c80f1dfadcdd
Support default_factory=list for write only / dynamic relationships

Fixed regression caused by the dataclasses change in :ticket:`12168`
where passing :paramref:`_orm.relationship.default_factory` as ``list``
to a relationship that used the :class:`_orm.WriteOnlyMapped` or
:class:`_orm.DynamicMapped` annotation would raise an error at mapper
configuration time, as these relationships have no ``collection_class``.
``list`` is now accepted for these relationships, which behave the same
as ordinary collections in this regard; the factory itself is never
invoked, and a newly constructed object begins with an empty
collection.  Documentation is added at :ref:`write_only_dataclasses`
illustrating the use of write only and dynamic relationships with ORM
mapped dataclasses.

Fixes: #13227
Change-Id: I809b408b0eabf0235f9d6e95871a85eba3917e61
doc/build/changelog/unreleased_21/13227.rst [new file with mode: 0644]
doc/build/orm/dataclasses.rst
doc/build/orm/large_collections.rst
lib/sqlalchemy/orm/relationships.py
lib/sqlalchemy/orm/writeonly.py
test/orm/declarative/test_dc_transforms.py
test/orm/declarative/test_dc_transforms_future_anno_sync.py