regression in 0.6: self-referencial Many-To-Many does not flush mutually dependant objects

Issue #1824 resolved
Former user created an issue

(original reporter: ged) See attached test case. I have very little time to spend on SA these days, so I didn't dig too deep into this, but this worked fine in 0.5.x. Note that since this is a M2M, the table rows are not dependent on each other, so post_update doesn't help.

Also, there is no error whatsoever. Part of the data is just silently ignored, hence the "highest" priority. Sorry if this turns out to be a mistake on my end (quite possible, given my very limited study of the problem).

Comments (3)

  1. Mike Bayer repo owner

    fun. confirmed as a regression, needs a unit test for commit

    diff -r 0707c94d630966ef677acafecf90f7c6884de1ce CHANGES
    --- a/CHANGES   Wed Jun 09 11:07:57 2010 -0400
    +++ b/CHANGES   Wed Jun 09 18:21:09 2010 -0400
    @@ -5,6 +5,11 @@
     =======
     0.6.2
     =====
    +- orm
    +  - Fixed flushes on self-referential bi-directional
    +    many-to-many relationships, regression from 0.5.
    +    #1824
    +    
     - sql
       - Fixed bug in Enum type which blew away native_enum
         flag when used with TypeDecorators or other adaption
    diff -r 0707c94d630966ef677acafecf90f7c6884de1ce lib/sqlalchemy/orm/dependency.py
    --- a/lib/sqlalchemy/orm/dependency.py  Wed Jun 09 11:07:57 2010 -0400
    +++ b/lib/sqlalchemy/orm/dependency.py  Wed Jun 09 18:21:09 2010 -0400
    @@ -870,7 +870,7 @@
             secondary_update = [        
             processed = self._get_reversed_processed_set(uowcommit)
    -        
    +        tmp = set()
             for state in states:
                 history = uowcommit.get_attribute_history(
                                         state, 
    @@ -890,8 +890,10 @@
                                             False, uowcommit)
                         secondary_delete.append(associationrow)
    
    -                if processed is not None:
    -                    processed.update((c, state) for c in history.non_added())
    +                tmp.update((c, state) for c in history.non_added())
    +
    +        if processed is not None:
    +            processed.update(tmp)
    
             self._run_crud(uowcommit, secondary_insert, 
                             secondary_update, secondary_delete)
    @@ -902,7 +904,8 @@
             secondary_update = [](]
    )
    
             processed = self._get_reversed_processed_set(uowcommit)
    -        
    +        tmp = set()
    +
             for state in states:
                 history = uowcommit.get_attribute_history(state, self.key)
                 if history:
    @@ -928,8 +931,7 @@
                                             False, uowcommit)
                         secondary_delete.append(associationrow)
    
    -                if processed is not None:
    -                    processed.update((c, state) for c in history.added + history.deleted)
    +                tmp.update((c, state) for c in history.added + history.deleted)
    
                 if not self.passive_updates and \
                         self._pks_changed(uowcommit, state):
    @@ -954,7 +956,9 @@
    
                         secondary_update.append(associationrow)
    
    -
    +        if processed is not None:
    +            processed.update(tmp)
    +            
             self._run_crud(uowcommit, secondary_insert, 
                             secondary_update, secondary_delete)
    
  2. Log in to comment