Created
          June 4, 2014 06:52 
        
      - 
      
- 
        Save loic/57028547e85f7fea928e to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py | |
| index 63da28d..9452b06 100644 | |
| --- a/django/db/models/fields/related.py | |
| +++ b/django/db/models/fields/related.py | |
| @@ -617,9 +617,12 @@ class ReverseSingleRelatedObjectDescriptor(object): | |
| if related is not None: | |
| setattr(related, self.field.related.get_cache_name(), None) | |
| - # Set the value of the related field | |
| - for lh_field, rh_field in self.field.related_fields: | |
| - try: | |
| + for lh_field, rh_field in self.field.related_fields: | |
| + setattr(instance, lh_field.attname, None) | |
| + | |
| + # Set the values of the related field. | |
| + else: | |
| + for lh_field, rh_field in self.field.related_fields: | |
| val = getattr(value, rh_field.attname) | |
| if val is None: | |
| raise ValueError( | |
| @@ -627,8 +630,6 @@ class ReverseSingleRelatedObjectDescriptor(object): | |
| (value, self.field.rel.to._meta.object_name) | |
| ) | |
| setattr(instance, lh_field.attname, val) | |
| - except AttributeError: | |
| - setattr(instance, lh_field.attname, None) | |
| # Since we already know what the related object is, seed the related | |
| # object caches now, too. This avoids another db hit if you get the | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment