Receive an object instance before that instance is updated.
Note that this method is called for all instances that are marked as
“dirty”, even those which have no net changes to their column-based
attributes. An object is marked as dirty when any of its column-based
attributes have a “set attribute” operation called or when any of its
collections are modified. If, at update time, no column-based
attributes have any net changes, no UPDATE statement will be issued.
This means that an instance being sent to before_update is not a
guarantee that an UPDATE statement will be issued (although you can
affect the outcome here).
To detect if the column-based attributes on the object have net
changes, and will therefore generate an UPDATE statement, use
object_session(instance).is_modified(instance,
include_collections=False).
Column-based attributes can be modified within this method
which will result in the new value being updated. However
no changes to the overall flush plan can be made, and
manipulation of the Session will not have the desired effect.
To manipulate the Session within an extension, use
SessionExtension.
The return value is only significant within the MapperExtension
chain; the parent mapper’s behavior isn’t modified by this method.