mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[4.1.x] Fixed #33996 -- Fixed CheckConstraint validation on NULL values.
Bug in667105877e. Thanks James Beith for the report. Backport ofe14d08cd89from main
This commit is contained in:
committed by
Mariusz Felisiak
parent
148d60de74
commit
be5e3b46f7
@@ -6,7 +6,7 @@ from django.db.models import F
|
||||
from django.db.models.constraints import BaseConstraint
|
||||
from django.db.models.functions import Lower
|
||||
from django.db.transaction import atomic
|
||||
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
|
||||
from django.test import SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature
|
||||
|
||||
from .models import (
|
||||
ChildModel,
|
||||
@@ -234,6 +234,23 @@ class CheckConstraintTests(TestCase):
|
||||
constraint.validate(Product, Product(price=501, discounted_price=5))
|
||||
constraint.validate(Product, Product(price=499, discounted_price=5))
|
||||
|
||||
@skipUnlessDBFeature("supports_comparing_boolean_expr")
|
||||
def test_validate_nullable_field_with_none(self):
|
||||
# Nullable fields should be considered valid on None values.
|
||||
constraint = models.CheckConstraint(
|
||||
check=models.Q(price__gte=0),
|
||||
name="positive_price",
|
||||
)
|
||||
constraint.validate(Product, Product())
|
||||
|
||||
@skipIfDBFeature("supports_comparing_boolean_expr")
|
||||
def test_validate_nullable_field_with_isnull(self):
|
||||
constraint = models.CheckConstraint(
|
||||
check=models.Q(price__gte=0) | models.Q(price__isnull=True),
|
||||
name="positive_price",
|
||||
)
|
||||
constraint.validate(Product, Product())
|
||||
|
||||
|
||||
class UniqueConstraintTests(TestCase):
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user