MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / after_update

Method after_update

lib/sqlalchemy/orm/events.py:1345–1415  ·  view source on GitHub ↗

Receive an object instance after an UPDATE 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

1343 """
1344
1345 def after_update(
1346 self, mapper: Mapper[_O], connection: Connection, target: _O
1347 ) -> None:
1348 """Receive an object instance after an UPDATE statement
1349 is emitted corresponding to that instance.
1350
1351 .. note:: this event **only** applies to the
1352 :ref:`session flush operation <session_flushing>`
1353 and does **not** apply to the ORM DML operations described at
1354 :ref:`orm_expression_update_delete`. To intercept ORM
1355 DML events, use :meth:`_orm.SessionEvents.do_orm_execute`.
1356
1357 This event is used to modify in-Python-only
1358 state on the instance after an UPDATE occurs, as well
1359 as to emit additional SQL statements on the given
1360 connection.
1361
1362 This method is called for all instances that are
1363 marked as "dirty", *even those which have no net changes
1364 to their column-based attributes*, and for which
1365 no UPDATE statement has proceeded. An object is marked
1366 as dirty when any of its column-based attributes have a
1367 "set attribute" operation called or when any of its
1368 collections are modified. If, at update time, no
1369 column-based attributes have any net changes, no UPDATE
1370 statement will be issued. This means that an instance
1371 being sent to :meth:`~.MapperEvents.after_update` is
1372 *not* a guarantee that an UPDATE statement has been
1373 issued.
1374
1375 To detect if the column-based attributes on the object have net
1376 changes, and therefore resulted in an UPDATE statement, use
1377 ``object_session(instance).is_modified(instance,
1378 include_collections=False)``.
1379
1380 The event is often called for a batch of objects of the
1381 same class after their UPDATE statements have been emitted at
1382 once in a previous step. In the extremely rare case that
1383 this is not desirable, the :class:`_orm.Mapper` can be
1384 configured with ``batch=False``, which will cause
1385 batches of instances to be broken up into individual
1386 (and more poorly performing) event->persist->event
1387 steps.
1388
1389 .. warning::
1390
1391 Mapper-level flush events only allow **very limited operations**,
1392 on attributes local to the row being operated upon only,
1393 as well as allowing any SQL to be emitted on the given
1394 :class:`_engine.Connection`. **Please read fully** the notes
1395 at :ref:`session_persistence_mapper` for guidelines on using
1396 these methods; generally, the :meth:`.SessionEvents.before_flush`
1397 method should be preferred for general on-flush changes.
1398
1399 :param mapper: the :class:`_orm.Mapper` which is the target
1400 of this event.
1401 :param connection: the :class:`_engine.Connection` being used to
1402 emit UPDATE statements for this instance. This

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected