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

Method before_mapper_configured

lib/sqlalchemy/orm/events.py:980–1028  ·  view source on GitHub ↗

Called right before a specific mapper is to be configured. The :meth:`.MapperEvents.before_mapper_configured` event is invoked for each mapper that is encountered when the :func:`_orm.configure_mappers` function proceeds through the current list of not-yet-configured

(
        self, mapper: Mapper[_O], class_: Type[_O]
    )

Source from the content-addressed store, hash-verified

978
979 @event._omit_standard_example
980 def before_mapper_configured(
981 self, mapper: Mapper[_O], class_: Type[_O]
982 ) -> None:
983 """Called right before a specific mapper is to be configured.
984
985 The :meth:`.MapperEvents.before_mapper_configured` event is invoked
986 for each mapper that is encountered when the
987 :func:`_orm.configure_mappers` function proceeds through the current
988 list of not-yet-configured mappers. It is similar to the
989 :meth:`.MapperEvents.mapper_configured` event, except that it's invoked
990 right before the configuration occurs, rather than afterwards.
991
992 The :meth:`.MapperEvents.before_mapper_configured` event includes
993 the special capability where it can force the configure step for a
994 specific mapper to be skipped; to use this feature, establish
995 the event using the ``retval=True`` parameter and return
996 the :attr:`.orm.interfaces.EXT_SKIP` symbol to indicate the mapper
997 should be left unconfigured::
998
999 from sqlalchemy import event
1000 from sqlalchemy.orm import EXT_SKIP
1001 from sqlalchemy.orm import DeclarativeBase
1002
1003
1004 class DontConfigureBase(DeclarativeBase):
1005 pass
1006
1007
1008 @event.listens_for(
1009 DontConfigureBase,
1010 "before_mapper_configured",
1011 # support return values for the event
1012 retval=True,
1013 # propagate the listener to all subclasses of
1014 # DontConfigureBase
1015 propagate=True,
1016 )
1017 def dont_configure(mapper, cls):
1018 return EXT_SKIP
1019
1020 .. seealso::
1021
1022 :meth:`.MapperEvents.before_configured`
1023
1024 :meth:`.MapperEvents.after_configured`
1025
1026 :meth:`.MapperEvents.mapper_configured`
1027
1028 """
1029
1030 def mapper_configured(self, mapper: Mapper[_O], class_: Type[_O]) -> None:
1031 r"""Called when a specific mapper has completed its own configuration

Callers 1

Calls

no outgoing calls

Tested by 1