• 
      

    Fix failures due to unsaved tracked instances in RelationCounterField.

    Review Request #7157 — Created April 2, 2015 and submitted

    Information

    Djblets
    release-0.8.x
    b4afe22...

    Reviewers

    Instances of models that were created but never saved caused some
    probelms for RelationCounterField. Since we can't listen for post_save
    on an instance, we must listen on a class and pass an instance to
    compare against. We then tried to disconnect that signal later, but only
    if we ever saved that instance.
    
    This meant two bad things were happening:
    
    1. Future saves from other instances of that class would trigger the
       same handler and hit an assertion.
    2. We had a reference to that instance, forever, unless it eventually
       saved, and kept its signal handler around forever as well.
    
    That assertion now lives within the conditionals checking if the signal
    handler is operating on the expected object, fixing case #1.
    
    For case #2, we no longer keep the instance around in the lambdas for
    comparison. Instead, we work on an instance ID. We then keep a weak
    reference to the instance in order to track when it falls out of scope,
    and disconnect the signal handler.
    
    The end result is that multiple instances from the same class won't
    break each other, nor will unsaved instances leak memory.

    The new unit tests both failed before this. After, they pass.

    Description From Last Updated

    local variable 'model1' is assigned to but never used

    reviewbotreviewbot

    local variable 'model' is assigned to but never used

    reviewbotreviewbot
    reviewbot
    1. Tool: Pyflakes
      Processed Files:
          djblets/db/tests/test_relation_counter_field.py
          djblets/db/fields.py
      
      
      
      Tool: PEP8 Style Checker
      Processed Files:
          djblets/db/tests/test_relation_counter_field.py
          djblets/db/fields.py
      
      
    2. Show all issues
       local variable 'model1' is assigned to but never used
      
    3. Show all issues
       local variable 'model' is assigned to but never used
      
    4. 
        
    chipx86
    reviewbot
    1. Tool: Pyflakes
      Processed Files:
          djblets/db/tests/test_relation_counter_field.py
          djblets/db/fields.py
      
      
      
      Tool: PEP8 Style Checker
      Processed Files:
          djblets/db/tests/test_relation_counter_field.py
          djblets/db/fields.py
      
      
    2. 
        
    brennie
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-0.8.x (ef003e7)