]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Fixed regression with callables as daclasses defaults
authorFederico Caselli <cfederico87@gmail.com>
Mon, 12 Jun 2023 20:55:15 +0000 (22:55 +0200)
committermike bayer <mike_mp@zzzcomputing.com>
Tue, 13 Jun 2023 23:48:08 +0000 (23:48 +0000)
commit017a43cb01b5bf93cd262e930627fb07410ef387
tree907cf77035f62463cd3ebeb47593b7eb70f0f48a
parentc781a27eecb730d688382e33e49e65b3fcaa2aaa
Fixed regression with callables as daclasses defaults

Fixed regression introduced in 2.0.16 by :ticket:`9879` where passing a
callable to the :paramref:`_orm.mapped_column.default` parameter of
:class:`_orm.mapped_column` while also setting ``init=False`` would
interpret this value as a Dataclass default value which would be assigned
directly to new instances of the object directly, bypassing the default
generator taking place as the as the :paramref:`_schema.Column.default`
value generator on the underlying :class:`_schema.Column`.  This condition
is now detected so that the previous behavior is maintained, however a
deprecation warning for this ambiguous use is emitted; to populate the
default generator for a :class:`_schema.Column`, the
:paramref:`_orm.mapped_column.insert_default` parameter should be used,
which disambiguates from the :paramref:`_orm.mapped_column.default`
parameter whose name is fixed as per pep-681.

Fixes: #9936
Change-Id: I7e2c1c723e4711ec470336fcb4867f41c40f9d6b
doc/build/changelog/unreleased_20/9936.rst [new file with mode: 0644]
lib/sqlalchemy/orm/interfaces.py
test/orm/declarative/test_dc_transforms.py