Ticket #11320: exclude-none-join.diff

File exclude-none-join.diff, 2.0 KB (added by Alex Gaynor, 15 years ago)

First stab at a patch, I think it fails in nested disjunctives and probably other edge cases though.

  • django/db/models/sql/query.py

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index 394e30b..2fb077b 100644
    a b class BaseQuery(object):  
    16271627                    entry.add((Constraint(alias, col, None), 'isnull', True), AND)
    16281628                    entry.negate()
    16291629                    self.where.add(entry, AND)
     1630            elif connector != OR and value:
     1631                if len(join_list) > 1:
     1632                    for alias in join_list:
     1633                        if self.alias_map[alias][JOIN_TYPE] == self.LOUTER:
     1634                            data = list(self.alias_map[alias])
     1635                            data[JOIN_TYPE] = self.INNER
     1636                            self.alias_map[alias] = tuple(data)
     1637                            break
    16301638
    16311639        if can_reuse is not None:
    16321640            can_reuse.update(join_list)
  • tests/regressiontests/queries/models.py

    diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
    index b5fa377..dc90879 100644
    a b class Plaything(models.Model):  
    271271    def __unicode__(self):
    272272        return self.name
    273273
     274class Venue(models.Model):
     275    name = models.CharField(max_length=100)
     276
     277class Event(models.Model):
     278    name = models.CharField(max_length=100)
     279    venue = models.ForeignKey(Venue, null=True)
     280   
     281    def __unicode__(self):
     282        return self.name
     283
    274284
    275285__test__ = {'API_TESTS':"""
    276286>>> generic = NamedCategory.objects.create(name="Generic")
    True  
    11431153>>> r.save()
    11441154>>> Ranking.objects.all()
    11451155[<Ranking: 3: a1>, <Ranking: 2: a2>, <Ranking: 1: a3>]
     1156
     1157>>> v = Venue.objects.create(name="Googleplex")
     1158>>> _ = Event.objects.create(name="Release Party")
     1159>>> _ = Event.objects.create(name="DjangCon 2008", venue=v)
     1160>>> 'LEFT OUTER JOIN' in Event.objects.exclude(venue__name='a').exclude(venue=None).query.as_sql()[0]
     1161False
    11461162"""}
    11471163
    11481164# In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__
Back to Top