From: E. Seiver <5547078+eseiver@users.noreply.github.com> Date: Wed, 29 Sep 2021 19:25:36 +0000 (-0700) Subject: clarifies that @reconstructor only applies to a single method X-Git-Tag: rel_1_4_26~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7114%2Fhead;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git clarifies that @reconstructor only applies to a single method --- 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.