#NEWLINE# def _flush( self , objects = None ) : #NEWLINE# #INDENT# dirty = self . _dirty_states #NEWLINE# if ( ( not dirty ) and ( not self . _deleted ) and ( not self . _new ) ) : #NEWLINE# #INDENT# self . identity_map . _modified . clear ( ) #NEWLINE# return #NEWLINE# #UNINDENT# flush_context = UOWTransaction ( self ) #NEWLINE# if self . dispatch . before_flush : #NEWLINE# #INDENT# self . dispatch . before_flush ( self , flush_context , objects ) #NEWLINE# dirty = self . _dirty_states #NEWLINE# #UNINDENT# deleted = set ( self . _deleted ) #NEWLINE# new = set ( self . _new ) #NEWLINE# dirty = set ( dirty ) . difference ( deleted ) #NEWLINE# if objects : #NEWLINE# #INDENT# objset = set ( ) #NEWLINE# for o in objects : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# state = attributes . instance_state ( o ) #NEWLINE# #UNINDENT# except exc . NO_STATE : #NEWLINE# #INDENT# raise exc . UnmappedInstanceError ( o ) #NEWLINE# #UNINDENT# objset . add ( state ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# objset = None #NEWLINE# #UNINDENT# processed = set ( ) #NEWLINE# if objset : #NEWLINE# #INDENT# proc = new . union ( dirty ) . intersection ( objset ) . difference ( deleted ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# proc = new . union ( dirty ) . difference ( deleted ) #NEWLINE# #UNINDENT# for state in proc : #NEWLINE# #INDENT# is_orphan = ( _state_mapper ( state ) . _is_orphan ( state ) and state . has_identity ) #NEWLINE# flush_context . register_object ( state , isdelete = is_orphan ) #NEWLINE# processed . add ( state ) #NEWLINE# #UNINDENT# if objset : #NEWLINE# #INDENT# proc = deleted . intersection ( objset ) . difference ( processed ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# proc = deleted . difference ( processed ) #NEWLINE# #UNINDENT# for state in proc : #NEWLINE# #INDENT# flush_context . register_object ( state , isdelete = True ) #NEWLINE# #UNINDENT# if ( not flush_context . has_work ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# flush_context . transaction = transaction = self . begin ( subtransactions = True ) #NEWLINE# try : #NEWLINE# #INDENT# self . _warn_on_events = True #NEWLINE# try : #NEWLINE# #INDENT# flush_context . execute ( ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# self . _warn_on_events = False #NEWLINE# #UNINDENT# self . dispatch . after_flush ( self , flush_context ) #NEWLINE# flush_context . finalize_flush_changes ( ) #NEWLINE# if ( ( not objects ) and self . identity_map . _modified ) : #NEWLINE# #INDENT# len_ = len ( self . identity_map . _modified ) #NEWLINE# statelib . InstanceState . _commit_all_states ( [ ( state , dirty . dict ) for state in self . identity_map . _modified ] , instance_dict = self . identity_map ) #NEWLINE# util . warn ( ( 'Attribute history events accumulated on %d previously clean instances within inner-flush event handlers have been reset, and will not result in database updates. Consider using set_committed_value() within inner-flush event handlers to avoid this warning.' % len_ ) ) #NEWLINE# #UNINDENT# self . dispatch . after_flush_postexec ( self , flush_context ) #NEWLINE# transaction . commit ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# with util . safe_reraise ( ) : #NEWLINE# #INDENT# transaction . rollback ( _capture_exception = True )