MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / after_insert

Method after_insert

lib/sqlalchemy/orm/events.py:1218–1270  ·  view source on GitHub ↗

Receive an object instance after an INSERT statement is emitted corresponding to that instance. .. note:: this event **only** applies to the :ref:`session flush operation <session_flushing>` and does **not** apply to the ORM DML operations described at

(
        self, mapper: Mapper[_O], connection: Connection, target: _O
    )

Source from the content-addressed store, hash-verified

1216 """
1217
1218 def after_insert(
1219 self, mapper: Mapper[_O], connection: Connection, target: _O
1220 ) -> None:
1221 """Receive an object instance after an INSERT statement
1222 is emitted corresponding to that instance.
1223
1224 .. note:: this event **only** applies to the
1225 :ref:`session flush operation <session_flushing>`
1226 and does **not** apply to the ORM DML operations described at
1227 :ref:`orm_expression_update_delete`. To intercept ORM
1228 DML events, use :meth:`_orm.SessionEvents.do_orm_execute`.
1229
1230 This event is used to modify in-Python-only
1231 state on the instance after an INSERT occurs, as well
1232 as to emit additional SQL statements on the given
1233 connection.
1234
1235 The event is often called for a batch of objects of the
1236 same class after their INSERT statements have been
1237 emitted at once in a previous step. In the extremely
1238 rare case that this is not desirable, the
1239 :class:`_orm.Mapper` object can be configured with ``batch=False``,
1240 which will cause batches of instances to be broken up
1241 into individual (and more poorly performing)
1242 event->persist->event steps.
1243
1244 .. warning::
1245
1246 Mapper-level flush events only allow **very limited operations**,
1247 on attributes local to the row being operated upon only,
1248 as well as allowing any SQL to be emitted on the given
1249 :class:`_engine.Connection`. **Please read fully** the notes
1250 at :ref:`session_persistence_mapper` for guidelines on using
1251 these methods; generally, the :meth:`.SessionEvents.before_flush`
1252 method should be preferred for general on-flush changes.
1253
1254 :param mapper: the :class:`_orm.Mapper` which is the target
1255 of this event.
1256 :param connection: the :class:`_engine.Connection` being used to
1257 emit INSERT statements for this instance. This
1258 provides a handle into the current transaction on the
1259 target database specific to this instance.
1260 :param target: the mapped instance being persisted. If
1261 the event is configured with ``raw=True``, this will
1262 instead be the :class:`.InstanceState` state-management
1263 object associated with the instance.
1264 :return: No return value is supported by this event.
1265
1266 .. seealso::
1267
1268 :ref:`session_persistence_events`
1269
1270 """
1271
1272 def before_update(
1273 self, mapper: Mapper[_O], connection: Connection, target: _O

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected