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

Function configure_mappers

lib/sqlalchemy/orm/mapper.py:4129–4197  ·  view source on GitHub ↗

Initialize the inter-mapper relationships of all mappers that have been constructed thus far across all :class:`_orm.registry` collections. The configure step is used to reconcile and initialize the :func:`_orm.relationship` linkages between mapped classes, as well as to invoke

()

Source from the content-addressed store, hash-verified

4127
4128
4129def configure_mappers() -> None:
4130 """Initialize the inter-mapper relationships of all mappers that
4131 have been constructed thus far across all :class:`_orm.registry`
4132 collections.
4133
4134 The configure step is used to reconcile and initialize the
4135 :func:`_orm.relationship` linkages between mapped classes, as well as to
4136 invoke configuration events such as the
4137 :meth:`_orm.MapperEvents.before_configured` and
4138 :meth:`_orm.MapperEvents.after_configured`, which may be used by ORM
4139 extensions or user-defined extension hooks.
4140
4141 Mapper configuration is normally invoked automatically, the first time
4142 mappings from a particular :class:`_orm.registry` are used, as well as
4143 whenever mappings are used and additional not-yet-configured mappers have
4144 been constructed. The automatic configuration process however is local only
4145 to the :class:`_orm.registry` involving the target mapper and any related
4146 :class:`_orm.registry` objects which it may depend on; this is
4147 equivalent to invoking the :meth:`_orm.registry.configure` method
4148 on a particular :class:`_orm.registry`.
4149
4150 By contrast, the :func:`_orm.configure_mappers` function will invoke the
4151 configuration process on all :class:`_orm.registry` objects that
4152 exist in memory, and may be useful for scenarios where many individual
4153 :class:`_orm.registry` objects that are nonetheless interrelated are
4154 in use.
4155
4156 .. versionchanged:: 1.4
4157
4158 As of SQLAlchemy 1.4.0b2, this function works on a
4159 per-:class:`_orm.registry` basis, locating all :class:`_orm.registry`
4160 objects present and invoking the :meth:`_orm.registry.configure` method
4161 on each. The :meth:`_orm.registry.configure` method may be preferred to
4162 limit the configuration of mappers to those local to a particular
4163 :class:`_orm.registry` and/or declarative base class.
4164
4165 Points at which automatic configuration is invoked include when a mapped
4166 class is instantiated into an instance, as well as when ORM queries
4167 are emitted using :meth:`.Session.query` or :meth:`_orm.Session.execute`
4168 with an ORM-enabled statement.
4169
4170 The mapper configure process, whether invoked by
4171 :func:`_orm.configure_mappers` or from :meth:`_orm.registry.configure`,
4172 provides several event hooks that can be used to augment the mapper
4173 configuration step. These hooks include:
4174
4175 * :meth:`.MapperEvents.before_configured` - called once before
4176 :func:`.configure_mappers` or :meth:`_orm.registry.configure` does any
4177 work; this can be used to establish additional options, properties, or
4178 related mappings before the operation proceeds.
4179
4180 * :meth:`.MapperEvents.mapper_configured` - called as each individual
4181 :class:`_orm.Mapper` is configured within the process; will include all
4182 mapper state except for backrefs set up by other mappers that are still
4183 to be configured.
4184
4185 * :meth:`.MapperEvents.after_configured` - called once after
4186 :func:`.configure_mappers` or :meth:`_orm.registry.configure` is

Calls 2

_configure_registriesFunction · 0.85
_all_registriesFunction · 0.85