Ticket #14601: promote_alias.diff

File promote_alias.diff, 2.6 KB (added by ryanbutterfield, 14 years ago)

promote_alias fix and tests

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

     
    641641        False, the join is only promoted if it is nullable, otherwise it is
    642642        always promoted.
    643643
    644         Returns True if the join was promoted.
     644        Returns True if the join was promoted or had been previously.
    645645        """
    646         if ((unconditional or self.alias_map[alias][NULLABLE]) and
    647                 self.alias_map[alias][JOIN_TYPE] != self.LOUTER):
    648             data = list(self.alias_map[alias])
    649             data[JOIN_TYPE] = self.LOUTER
    650             self.alias_map[alias] = tuple(data)
     646        if unconditional or self.alias_map[alias][NULLABLE]:
     647            if self.alias_map[alias][JOIN_TYPE] != self.LOUTER:
     648                data = list(self.alias_map[alias])
     649                data[JOIN_TYPE] = self.LOUTER
     650                self.alias_map[alias] = tuple(data)
    651651            return True
    652652        return False
    653653
  • tests/modeltests/promote_alias/__init__.py

     
     1
  • tests/modeltests/promote_alias/models.py

     
     1"""
     2Testing query promote_alias bug.
     3"""
     4
     5from django.db import models
     6
     7class User(models.Model):
     8    first_name = models.CharField(max_length=100)
     9    last_name = models.CharField(max_length=100)
     10   
     11class Person(models.Model):
     12    user = models.ForeignKey(User)
     13
     14class Item(models.Model):
     15    person = models.ForeignKey(Person, null=True)
     16    amount = models.IntegerField()
     17
     18
     19__test__ = {'API_TESTS':"""
     20>>> from django.db.models import Q
     21
     22>>> Item.objects.create(person=None, amount=123)
     23<Item: Item object>
     24
     25>>> Item.objects.values('amount', 'person__user__first_name', 'person__user__last_name')
     26[{'amount': 123, 'person__user__last_name': None, 'person__user__first_name': None}]
     27
     28>>> Item.objects.filter(Q(person__isnull=True) | Q(person__isnull=False))
     29[<Item: Item object>]
     30
     31>>> Item.objects.filter(Q(person__isnull=True) | Q(person__isnull=False)).values('amount', 'person__user__first_name', 'person__user__last_name')
     32[{'amount': 123, 'person__user__last_name': None, 'person__user__first_name': None}]
     33
     34"""}
Back to Top