Ver código fonte

Refs #35234 -- Removed CheckConstraint.check per deprecation timeline.

Sarah Boyce 3 meses atrás
pai
commit
85750bd2f8

+ 1 - 33
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 (

+ 0 - 4
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``
 ====================
 

+ 2 - 0
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.

+ 0 - 19
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"),