#NEWLINE# def _finalize_insert_update_commands( base_mapper , uowtransaction , states ) : #NEWLINE# #INDENT# 'finalize state on states that have been inserted or updated,\n    including calling after_insert/after_update events.\n\n    ' #NEWLINE# for ( state , state_dict , mapper , connection , has_identity ) in states : #NEWLINE# #INDENT# if mapper . _readonly_props : #NEWLINE# #INDENT# readonly = state . unmodified_intersection ( [ p . key for p in mapper . _readonly_props if ( p . expire_on_flush or ( p . key not in state . dict ) ) ] ) #NEWLINE# if readonly : #NEWLINE# #INDENT# state . _expire_attributes ( state . dict , readonly ) #NEWLINE# #UNINDENT# #UNINDENT# toload_now = [ ] #NEWLINE# if base_mapper . eager_defaults : #NEWLINE# #INDENT# toload_now . extend ( state . _unloaded_non_object ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( mapper . version_id_col is not None ) and ( mapper . version_id_generator is False ) ) : #NEWLINE# #INDENT# if ( mapper . _version_id_prop . key in state . unloaded ) : #NEWLINE# #INDENT# toload_now . extend ( [ mapper . _version_id_prop . key ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if toload_now : #NEWLINE# #INDENT# state . key = base_mapper . _identity_key_from_state ( state ) #NEWLINE# loading . load_on_ident ( uowtransaction . session . query ( base_mapper ) , state . key , refresh_state = state , only_load_props = toload_now ) #NEWLINE# #UNINDENT# if ( not has_identity ) : #NEWLINE# #INDENT# mapper . dispatch . after_insert ( mapper , connection , state ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mapper . dispatch . after_update ( mapper , connection , state )