From d496639613382a0140f2e2260b82979255a28ffd Mon Sep 17 00:00:00 2001 From: "E. Seiver" <5547078+eseiver@users.noreply.github.com> Date: Wed, 29 Sep 2021 12:25:36 -0700 Subject: [PATCH] clarifies that @reconstructor only applies to a single method --- doc/build/orm/constructors.rst | 4 ++-- lib/sqlalchemy/orm/mapper.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/build/orm/constructors.rst b/doc/build/orm/constructors.rst index 0d8ed471c7..b78b0f0cb9 100644 --- a/doc/build/orm/constructors.rst +++ b/doc/build/orm/constructors.rst @@ -21,7 +21,7 @@ If you need to do some setup on database-loaded instances before they're ready to use, there is an event hook known as :meth:`.InstanceEvents.load` which can achieve this; it is also available via a class-specific decorator called :func:`_orm.reconstructor`. When using :func:`_orm.reconstructor`, -the mapper will invoke the decorated method with no +the mapper will invoke a single decorated method with no arguments every time it loads or reconstructs an instance of the class. This is useful for recreating transient properties that are normally assigned in @@ -45,7 +45,7 @@ loaded during a :class:`~sqlalchemy.orm.query.Query` operation as in ``query(MyMappedClass).one()``, ``init_on_load`` is called. Any method may be tagged as the :func:`_orm.reconstructor`, even -the ``__init__`` method itself. It is invoked after all immediate +the ``__init__`` method itself, but only one method may be tagged as such. It is invoked after all immediate column-level attributes are loaded as well as after eagerly-loaded scalar relationships. Eagerly loaded collections may be only partially populated or not populated at all, depending on the kind of eager loading used. diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 7f111b2374..1aa6666a55 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -3515,7 +3515,7 @@ def _dispose_registries(registries, cascade): def reconstructor(fn): """Decorate a method as the 'reconstructor' hook. - Designates a method as the "reconstructor", an ``__init__``-like + Designates a single method as the "reconstructor", an ``__init__``-like method that will be called by the ORM after the instance has been loaded from the database or otherwise reconstituted. -- 2.47.2