Ticket #13815: 13815_2.patch

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

Updated patch with unittest instead of doctest

  • tests/regressiontests/null_queries/tests.py

     
    6767            ['<Inner: Inner object>']
    6868        )
    6969
     70        # Ticket #13815: check if <reverse>_isnull=False does not produce
     71        # faulty empty lists
     72        objB = OuterB.objects.create(data="reverse")
     73        self.assertQuerysetEqual(
     74            OuterB.objects.filter(inner__isnull=False),
     75            []
     76        )
     77        _ = Inner.objects.create(first=obj)
     78        self.assertQuerysetEqual(
     79            OuterB.objects.exclude(inner__isnull=False),
     80            ['<OuterB: OuterB object>']
     81        )
  • 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       
    14221429        self.add_filter(('%s__in' % prefix, query), negate=True, trim=True,
    14231430                can_reuse=can_reuse)
    14241431
Back to Top