﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33595	Check Constraint on nullable BooleanField should not be simplified	Peter Law	nobody	"Given a model like:

{{{#!python
class Foo(models.Model):
    it_exists = models.BooleanField(null=True)
    class Meta:
        constraints = [
            models.constraints.CheckConstraint(
                check=models.Q(it_exists=True),
                name=""exists_constraint"",
            ),
        ]
}}}

The constraint will allow both True and None values, yet that isn't at all obvious from the declaration.

I'm using Postgres 11 and the resulting check is simplified (in terms of the SQL from the migration) down to something like `CHECK ((""it_exists""))` (I've got a few other things in my actual constraint, but this what I see for the nullable boolean field).

This appears to end up allowing database NULL values to act as truthy values, which is undesirable (even if something which SQL allows).

I would have expected that the constraint would be more like `""it_exists"" = TRUE`, which I don't think would allow NULL values to pass the check.

It's possible to work around this by adding an explicit check (i.e: not-null-and-equals-true), though it would be great if the default behaviour was more in line with expectations."	Bug	closed	Database layer (models, ORM)	3.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
