diff --git a/django/db/models/constraints.py b/django/db/models/constraints.py index 6f9bf66dd7..16606e1898 100644 --- a/django/db/models/constraints.py +++ b/django/db/models/constraints.py @@ -1,4 +1,3 @@ -import warnings from enum import Enum from types import NoneType @@ -12,7 +11,6 @@ from django.db.models.lookups import Exact, IsNull from django.db.models.query_utils import Q from django.db.models.sql.query import Query from django.db.utils import DEFAULT_DB_ALIAS -from django.utils.deprecation import RemovedInDjango60Warning from django.utils.translation import gettext_lazy as _ __all__ = ["BaseConstraint", "CheckConstraint", "Deferrable", "UniqueConstraint"] @@ -130,26 +128,14 @@ class BaseConstraint: class CheckConstraint(BaseConstraint): - # RemovedInDjango60Warning: when the deprecation ends, replace with - # def __init__( - # self, *, condition, name, violation_error_code=None, violation_error_message=None - # ) def __init__( self, *, + condition, name, - condition=None, - check=None, violation_error_code=None, violation_error_message=None, ): - if check is not None: - warnings.warn( - "CheckConstraint.check is deprecated in favor of `.condition`.", - RemovedInDjango60Warning, - stacklevel=2, - ) - condition = check self.condition = condition if not getattr(condition, "conditional", False): raise TypeError( @@ -161,24 +147,6 @@ class CheckConstraint(BaseConstraint): violation_error_message=violation_error_message, ) - def _get_check(self): - warnings.warn( - "CheckConstraint.check is deprecated in favor of `.condition`.", - RemovedInDjango60Warning, - stacklevel=2, - ) - return self.condition - - def _set_check(self, value): - warnings.warn( - "CheckConstraint.check is deprecated in favor of `.condition`.", - RemovedInDjango60Warning, - stacklevel=2, - ) - self.condition = value - - check = property(_get_check, _set_check) - def _check(self, model, connection): errors = [] if not ( diff --git a/docs/ref/models/constraints.txt b/docs/ref/models/constraints.txt index 897c122f05..99e5332ca3 100644 --- a/docs/ref/models/constraints.txt +++ b/docs/ref/models/constraints.txt @@ -123,10 +123,6 @@ ensures the age field is never less than 18. CheckConstraint(condition=Q(age__gte=18) | Q(age__isnull=True), name="age_gte_18") -.. deprecated:: 5.1 - - The ``check`` attribute is deprecated in favor of ``condition``. - ``UniqueConstraint`` ==================== diff --git a/docs/releases/6.0.txt b/docs/releases/6.0.txt index 39a81e60e3..6969aed7f4 100644 --- a/docs/releases/6.0.txt +++ b/docs/releases/6.0.txt @@ -314,3 +314,5 @@ to remove usage of these features. ``Model.asave()`` is removed. * The setter for ``django.contrib.gis.gdal.OGRGeometry.coord_dim`` is removed. + +* The ``check`` keyword argument of ``CheckConstraint`` is removed. diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py index 4cf5a748a7..51f09f2937 100644 --- a/tests/constraints/tests.py +++ b/tests/constraints/tests.py @@ -7,8 +7,6 @@ from django.db.models.constraints import BaseConstraint, UniqueConstraint from django.db.models.functions import Abs, Lower, Sqrt, Upper from django.db.transaction import atomic from django.test import SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature -from django.test.utils import ignore_warnings -from django.utils.deprecation import RemovedInDjango60Warning from .models import ( ChildModel, @@ -399,23 +397,6 @@ class CheckConstraintTests(TestCase): constraint.validate(model, invalid_product, exclude={"price"}) constraint.validate(model, invalid_product, exclude={"rebate"}) - def test_check_deprecation(self): - msg = "CheckConstraint.check is deprecated in favor of `.condition`." - condition = models.Q(foo="bar") - with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx: - constraint = models.CheckConstraint(name="constraint", check=condition) - self.assertEqual(ctx.filename, __file__) - with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx: - self.assertIs(constraint.check, condition) - self.assertEqual(ctx.filename, __file__) - other_condition = models.Q(something="else") - with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx: - constraint.check = other_condition - self.assertEqual(ctx.filename, __file__) - with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx: - self.assertIs(constraint.check, other_condition) - self.assertEqual(ctx.filename, __file__) - def test_database_default(self): models.CheckConstraint( condition=models.Q(field_with_db_default="field_with_db_default"),