Django

Code

Changeset 7742

Show
Ignore:
Timestamp:
06/25/08 21:20:45 (5 months ago)
Author:
mtredinnick
Message:

Removed the bulk of the sanity checking when merging QuerySets?.

It was causing too many inconvenient and unintended problems when merging
legitimate subclasses (e.g. with geo-django classes). There's still a hook
there that we use when merging ValueQuerySets?, but if you try to merge two
disparate QuerySets? and it breaks all that happens is you get to keep both
pieces. We're no longer penalising the useful usages just for the people who
aren't concentrating.

Fixed #7113.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/query.py

    r7739 r7742  
    3737        Adds an item. 
    3838        model is the class of the object being added, 
    39         pk is the primary key, obj is the object itself,  
     39        pk is the primary key, obj is the object itself, 
    4040        parent_model is the model of the parent object 
    4141        that this object was reached through, nullable should 
     
    7878    def ordered_keys(self): 
    7979        """ 
    80         Returns the models in the order that they should be  
     80        Returns the models in the order that they should be 
    8181        dealth with i.e. models with no dependencies first. 
    8282        """ 
     
    9393            if not found: 
    9494                raise CyclicDependency("There is a cyclic dependency of items to be processed.") 
    95              
     95 
    9696        return dealt_with.keys() 
    9797 
     
    584584    def _merge_sanity_check(self, other): 
    585585        """ 
    586         Checks that we are merging two comparable queryset classes. 
    587         """ 
    588         if self.__class__ is not other.__class__: 
    589             raise TypeError("Cannot merge querysets of different types ('%s' and '%s'.
    590                     % (self.__class__.__name__, other.__class__.__name__)) 
     586        Checks that we are merging two comparable queryset classes. By default 
     587        this does nothing, but see the ValuesQuerySet for an example of where 
     588        it's useful. 
     589        ""
     590        pass 
    591591 
    592592class ValuesQuerySet(QuerySet): 
     
    600600 
    601601    def iterator(self): 
    602         if (not self.extra_names and  
     602        if (not self.extra_names and 
    603603            len(self.field_names) != len(self.model._meta.fields)): 
    604604            self.query.trim_extra_select(self.extra_names) 
     
    774774        # if there is a cyclic dependency, we cannot in general delete 
    775775        # the objects.  However, if an appropriate transaction is set 
    776         # up, or if the database is lax enough, it will succeed.  
     776        # up, or if the database is lax enough, it will succeed. 
    777777        # So for now, we go ahead and try anway. 
    778778        ordered_classes = seen_objs.unordered_keys()