Ticket #18726: test_ticket_18726.diff

File test_ticket_18726.diff, 2.2 KB (added by Jonas Kölker, 11 years ago)

(The code from comment:8)

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

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index c3c8e55..8f74b1d 100644
    a b class Query(object):  
    18821882        if self.alias_map[self.tables[pos + 1]].join_type != self.LOUTER:
    18831883            select_fields = [r[0] for r in join_field.related_fields]
    18841884            select_alias = self.tables[pos + 1]
    1885             self.unref_alias(self.tables[pos])
     1885            # self.unref_alias(self.tables[pos])
    18861886            extra_restriction = join_field.get_extra_restriction(
    18871887                self.where_class, None, self.tables[pos + 1])
    18881888            if extra_restriction:
  • tests/queries/tests.py

    diff --git a/tests/queries/tests.py b/tests/queries/tests.py
    index 338ec06..a8a87b8 100644
    a b class Queries1Tests(BaseQuerysetTest):  
    9999        # So, 'U0."id"' is referenced twice.
    100100        self.assertTrue(str(qs4.query).lower().count('u0'), 2)
    101101
     102    def test_ticket_18726(self):
     103        a = ObjectA.objects.create(name="alpha")
     104        b = ObjectB.objects.create(name="beta", objecta=a, num=int())
     105        c = ObjectC.objects.create(name="charlie", objectb=b, objecta=None)
     106
     107        def test(*args, **kwds):
     108            ObjectB.objects.filter(*args, **kwds).count()
     109            try: ObjectB.objects.exclude(*args, **kwds).count()
     110            except DatabaseError as e: self.fail(repr(e))
     111
     112        test(objecta__objectb__name='beta')
     113        test(objectc__objectb__name=F('name'))
     114        #test(objecta__objectb__name=F('name'))
     115
     116        test(objecta__objectb__name=F('objecta__name'))
     117        test(objecta__objectb__name=F('objecta__objectb__name'))
     118        test(objecta__objectb__name=F('objectc__objectb__name'))
     119        test(objecta__objectb__name=F('objectc__objectb__objecta__name'))
     120        #test(objecta__objectb__name=F('objectc__name'))
     121
     122        test(name=F('objecta__objectb__name'))
     123        test(objecta__name=F('objecta__objectb__name'))
     124        #test(objectc__name=F('objecta__objectb__name'))
     125
    102126    def test_ticket1050(self):
    103127        self.assertQuerysetEqual(
    104128            Item.objects.filter(tags__isnull=True),
Back to Top