MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / reconstructor

Function reconstructor

lib/sqlalchemy/orm/mapper.py:4321–4348  ·  view source on GitHub ↗

Decorate a method as the 'reconstructor' hook. 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. .. tip:: The :func:`_orm.reconstruc

(fn: _Fn)

Source from the content-addressed store, hash-verified

4319
4320
4321def reconstructor(fn: _Fn) -> _Fn:
4322 """Decorate a method as the 'reconstructor' hook.
4323
4324 Designates a single method as the "reconstructor", an ``__init__``-like
4325 method that will be called by the ORM after the instance has been
4326 loaded from the database or otherwise reconstituted.
4327
4328 .. tip::
4329
4330 The :func:`_orm.reconstructor` decorator makes use of the
4331 :meth:`_orm.InstanceEvents.load` event hook, which can be
4332 used directly.
4333
4334 The reconstructor will be invoked with no arguments. Scalar
4335 (non-collection) database-mapped attributes of the instance will
4336 be available for use within the function. Eagerly-loaded
4337 collections are generally not yet available and will usually only
4338 contain the first element. ORM state changes made to objects at
4339 this stage will not be recorded for the next flush() operation, so
4340 the activity within a reconstructor should be conservative.
4341
4342 .. seealso::
4343
4344 :meth:`.InstanceEvents.load`
4345
4346 """
4347 fn.__sa_reconstructor__ = True # type: ignore[attr-defined]
4348 return fn
4349
4350
4351def validates(

Callers 1

UserClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected