Django

Code

Changeset 7760

Show
Ignore:
Timestamp:
06/26/08 00:34:26 (2 months ago)
Author:
mtredinnick
Message:

Fixed #7076 -- Include NULL values when excluding non-NULL items.

Based on a patch from emulbreh.

Files:

Legend:

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

    r7741 r7760  
    10461046 
    10471047        self.where.add((alias, col, field, lookup_type, value), connector) 
     1048 
    10481049        if negate: 
    10491050            for alias in join_list: 
    10501051                self.promote_alias(alias) 
    1051             if final > 1 and lookup_type != 'isnull': 
    1052                 for alias in join_list: 
    1053                     if self.alias_map[alias] == self.LOUTER: 
    1054                         j_col = self.alias_map[alias][RHS_JOIN_COL] 
    1055                         entry = Node([(alias, j_col, None, 'isnull', True)]) 
    1056                         entry.negate() 
    1057                         self.where.add(entry, AND) 
    1058                         break 
     1052            if lookup_type != 'isnull': 
     1053                if final > 1: 
     1054                    for alias in join_list: 
     1055                        if self.alias_map[alias][JOIN_TYPE] == self.LOUTER: 
     1056                            j_col = self.alias_map[alias][RHS_JOIN_COL] 
     1057                            entry = Node([(alias, j_col, None, 'isnull', True)]) 
     1058                            entry.negate() 
     1059                            self.where.add(entry, AND) 
     1060                            break 
     1061                elif not (lookup_type == 'in' and not value): 
     1062                    # Leaky abstraction artifact: We have to specifically 
     1063                    # exclude the "foo__in=[]" case from this handling, because 
     1064                    # it's short-circuited in the Where class. 
     1065                    entry = Node([(alias, col, field, 'isnull', True)]) 
     1066                    entry.negate() 
     1067                    self.where.add(entry, AND) 
     1068 
    10591069        if can_reuse is not None: 
    10601070            can_reuse.update(join_list) 
  • django/trunk/tests/regressiontests/queries/models.py

    r7743 r7760  
    757757u'd2' 
    758758 
     759Bug #7076 -- excluding shouldn't eliminate NULL entries. 
     760>>> Item.objects.exclude(modified=time1).order_by('name') 
     761[<Item: four>, <Item: three>, <Item: two>] 
     762>>> Tag.objects.exclude(parent__name=t1.name) 
     763[<Tag: t1>, <Tag: t4>, <Tag: t5>] 
     764 
    759765"""} 
    760766