]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Fix adding property to mapper before mapping is complete
authorG Allajmi <ghaith.ger@gmail.com>
Mon, 8 Dec 2025 13:03:49 +0000 (08:03 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 9 Dec 2025 19:07:31 +0000 (14:07 -0500)
commite4a802f99a0bca813dd29e8dc88bb5e5aaddff93
tree4735a5f3120ecb27f53b7412cb14e85ad65af6a9
parentf9f07ce096910d375ebdf65a63a405d900a5d24b
Fix adding property to mapper before mapping is complete

Fixed issue where calling :meth:`.Mapper.add_property` within mapper event
hooks such as :meth:`.MapperEvents.instrument_class`,
:meth:`.MapperEvents.after_mapper_constructed`, or
:meth:`.MapperEvents.before_mapper_configured` would raise an
``AttributeError`` because the mapper's internal property collections were
not yet initialized. The :meth:`.Mapper.add_property` method now handles
early-stage property additions correctly, allowing properties including
column properties, deferred columns, and relationships to be added during
mapper initialization events.  Pull request courtesy G Allajmi.

Fixes: #12858
Closes: #13023
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13023
Pull-request-sha: fa9a0ae4bb07819307e6c9d6ec5fd4c9706bf67e

Change-Id: Ibb794c401102a8d23d157b40353f272d5735b49a
doc/build/changelog/unreleased_20/12858.rst [new file with mode: 0644]
lib/sqlalchemy/orm/mapper.py
test/orm/test_mapper.py