diff options
| author | David Sanders <shang.xiao.sanders@gmail.com> | 2022-09-09 00:02:58 +1000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-09-13 12:48:31 +0200 |
| commit | e14d08cd894e9d91cb5d9f44ba7532c1a223f458 (patch) | |
| tree | a524445fadbda60124a63468c643f31639d794fc /django/db/models | |
| parent | b731e8841558ee4caaba766c83f34ea9c7004f8b (diff) | |
Fixed #33996 -- Fixed CheckConstraint validation on NULL values.
Bug in 667105877e6723c6985399803a364848891513cc.
Thanks James Beith for the report.
Diffstat (limited to 'django/db/models')
| -rw-r--r-- | django/db/models/query_utils.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index 5562303e00..4a83fc380d 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -11,7 +11,7 @@ import logging from collections import namedtuple from django.core.exceptions import FieldError -from django.db import DEFAULT_DB_ALIAS, DatabaseError +from django.db import DEFAULT_DB_ALIAS, DatabaseError, connections from django.db.models.constants import LOOKUP_SEP from django.utils import tree @@ -115,7 +115,8 @@ class Q(tree.Node): matches against the expressions. """ # Avoid circular imports. - from django.db.models import Value + from django.db.models import BooleanField, Value + from django.db.models.functions import Coalesce from django.db.models.sql import Query from django.db.models.sql.constants import SINGLE @@ -126,7 +127,10 @@ class Q(tree.Node): query.add_annotation(value, name, select=False) query.add_annotation(Value(1), "_check") # This will raise a FieldError if a field is missing in "against". - query.add_q(self) + if connections[using].features.supports_comparing_boolean_expr: + query.add_q(Q(Coalesce(self, True, output_field=BooleanField()))) + else: + query.add_q(self) compiler = query.get_compiler(using=using) try: return compiler.execute_sql(SINGLE) is not None |
