Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0bfaf6e

Browse files
committed
Improve documentation for refresh_flush event
This event does not include INSERTed primary key columns and additionally will always be limited to default/onupdate columns. Note better choices for interception of INSERT events. Change-Id: I22b71ca1b336d4b098af075cc4694c55387b64f3 (cherry picked from commit 944fa69)
1 parent 2ba70a6 commit 0bfaf6e

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

lib/sqlalchemy/orm/events.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,27 @@ def refresh(self, target, context, attrs):
340340
"""
341341

342342
def refresh_flush(self, target, flush_context, attrs):
343-
"""Receive an object instance after one or more attributes have
344-
been refreshed within the persistence of the object.
343+
"""Receive an object instance after one or more attributes that
344+
contain a column-level default or onupdate handler have been refreshed
345+
during persistence of the object's state.
345346
346347
This event is the same as :meth:`.InstanceEvents.refresh` except
347-
it is invoked within the unit of work flush process, and the values
348-
here typically come from the process of handling an INSERT or
349-
UPDATE, such as via the RETURNING clause or from Python-side default
350-
values.
348+
it is invoked within the unit of work flush process, and includes
349+
only non-primary-key columns that have column level default or
350+
onupdate handlers, including Python callables as well as server side
351+
defaults and triggers which may be fetched via the RETURNING clause.
352+
353+
.. note::
354+
355+
While the :meth:`.InstanceEvents.refresh_flush` event is triggered
356+
for an object that was INSERTed as well as for an object that was
357+
UPDATEd, the event is geared primarily towards the UPDATE process;
358+
it is mostly an internal artifact that INSERT actions can also
359+
trigger this event, and note that **primary key columns for an
360+
INSERTed row are explicitly omitted** from this event. In order to
361+
intercept the newly INSERTed state of an object, the
362+
:meth:`.SessionEvents.pending_to_persistent` and
363+
:meth:`.MapperEvents.after_insert` are better choices.
351364
352365
.. versionadded:: 1.0.5
353366
@@ -360,6 +373,12 @@ def refresh_flush(self, target, flush_context, attrs):
360373
:param attrs: sequence of attribute names which
361374
were populated.
362375
376+
.. seealso::
377+
378+
:ref:`orm_server_defaults`
379+
380+
:ref:`metadata_defaults_toplevel`
381+
363382
"""
364383

365384
def expire(self, target, attrs):

0 commit comments

Comments
 (0)