Ticket #15823: 15823.diff

File 15823.diff, 3.0 KB (added by Dan Watson, 13 years ago)
  • django/db/models/sql/query.py

     
    452452                # An unused alias.
    453453                continue
    454454            promote = (rhs.alias_map[alias][JOIN_TYPE] == self.LOUTER)
    455             new_alias = self.join(rhs.rev_join_map[alias],
     455            lhs, table, lhs_col, col = rhs.rev_join_map[alias]
     456            # If the left side of the join was already relabeled, use the
     457            # updated alias.
     458            if lhs in change_map:
     459                lhs = change_map[lhs]
     460            new_alias = self.join((lhs, table, lhs_col, col),
    456461                    (conjunction and not first), used, promote, not conjunction)
    457462            used.add(new_alias)
    458463            change_map[alias] = new_alias
  • tests/regressiontests/null_fk/tests.py

     
    11from django.test import TestCase
     2from django.db.models import Q
    23
    34from regressiontests.null_fk.models import *
    45
     
    4041            ],
    4142            transform = lambda c: (c.id, c.comment_text, repr(c.post))
    4243        )
     44
     45    def test_combine_isnull(self):
     46        item = Item.objects.create(title='Some Item')
     47        pv = PropertyValue.objects.create(label='Some Value')
     48        item.props.create(key='a', value=pv)
     49        item.props.create(key='b') # value=NULL
     50        q1 = Q(props__key='a', props__value=pv)
     51        q2 = Q(props__key='b', props__value__isnull=True)
     52
     53        # Each of these individually should return the item.
     54        self.assertEqual(Item.objects.get(q1), item)
     55        self.assertEqual(Item.objects.get(q2), item)
     56
     57        # Logically, qs1 and qs2, and qs3 and qs4 should be the same.
     58        qs1 = Item.objects.filter(q1) & Item.objects.filter(q2)
     59        qs2 = Item.objects.filter(q2) & Item.objects.filter(q1)
     60        qs3 = Item.objects.filter(q1) | Item.objects.filter(q2)
     61        qs4 = Item.objects.filter(q2) | Item.objects.filter(q1)
     62
     63        # Regression test for #15823.
     64        self.assertEqual(list(qs1), list(qs2))
     65        self.assertEqual(list(qs3), list(qs4))
  • tests/regressiontests/null_fk/models.py

     
    3131
    3232    def __unicode__(self):
    3333        return self.comment_text
     34
     35# Ticket 15823
     36
     37class Item(models.Model):
     38    title = models.CharField(max_length=100)
     39
     40class PropertyValue(models.Model):
     41    label = models.CharField(max_length=100)
     42
     43class Property(models.Model):
     44    item = models.ForeignKey(Item, related_name='props')
     45    key = models.CharField(max_length=100)
     46    value = models.ForeignKey(PropertyValue, null=True)
Back to Top