Code

Ticket #13815: 13815.patch

File 13815.patch, 1.4 KB (added by bpeschier, 4 years ago)

Patch + extension of null_queries doctest

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

     
    14191419        query.bump_prefix() 
    14201420        query.clear_ordering(True) 
    14211421        query.set_start(prefix) 
     1422        # Adding extra check to make sure the selected field will not be null 
     1423        # since we are adding a IN <subquery> clause. This prevents the 
     1424        # database from tripping over IN (...,NULL,...) selects and returning 
     1425        # nothing 
     1426        alias, col = query.select[0] 
     1427        query.where.add((Constraint(alias, col, None), 'isnull', False), AND) 
     1428        # end of hack 
    14221429        self.add_filter(('%s__in' % prefix, query), negate=True, trim=True, 
    14231430                can_reuse=can_reuse) 
    14241431 
  • tests/regressiontests/null_queries/models.py

     
    7777>>> _ = Inner.objects.create(first=obj) 
    7878>>> Inner.objects.filter(first__inner__second=None) 
    7979[<Inner: Inner object>] 
     80>>> objB = OuterB.objects.create(data="reverse") 
     81>>> OuterB.objects.filter(inner__isnull=False) 
     82[] 
     83>>> _ = Inner.objects.create(first=obj) 
     84>>> OuterB.objects.exclude(inner__isnull=False) 
     85[<OuterB: OuterB object>] 
    8086 
    81  
    8287"""}