From b5a6c93a180e2c213e42f30a30bf63548a248957 Mon Sep 17 00:00:00 2001 From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:32:08 +0100 Subject: [PATCH] Refs #34355 -- Removed support for positional arguments in BaseConstraint per deprecation timeline. --- django/db/models/constraints.py | 23 +---------------------- docs/ref/models/constraints.txt | 4 ---- docs/releases/6.0.txt | 2 +- tests/constraints/tests.py | 10 ---------- 4 files changed, 2 insertions(+), 37 deletions(-) diff --git a/django/db/models/constraints.py b/django/db/models/constraints.py index 1601fc9933..6f9bf66dd7 100644 --- a/django/db/models/constraints.py +++ b/django/db/models/constraints.py @@ -25,19 +25,9 @@ class BaseConstraint: non_db_attrs = ("violation_error_code", "violation_error_message") - # RemovedInDjango60Warning: When the deprecation ends, replace with: - # def __init__( - # self, *, name, violation_error_code=None, violation_error_message=None - # ): def __init__( - self, *args, name=None, violation_error_code=None, violation_error_message=None + self, *, name, violation_error_code=None, violation_error_message=None ): - # RemovedInDjango60Warning. - if name is None and not args: - raise TypeError( - f"{self.__class__.__name__}.__init__() missing 1 required keyword-only " - f"argument: 'name'" - ) self.name = name if violation_error_code is not None: self.violation_error_code = violation_error_code @@ -45,17 +35,6 @@ class BaseConstraint: self.violation_error_message = violation_error_message else: self.violation_error_message = self.default_violation_error_message - # RemovedInDjango60Warning. - if args: - warnings.warn( - f"Passing positional arguments to {self.__class__.__name__} is " - f"deprecated.", - RemovedInDjango60Warning, - stacklevel=2, - ) - for arg, attr in zip(args, ["name", "violation_error_message"]): - if arg: - setattr(self, attr, arg) @property def contains_expressions(self): diff --git a/docs/ref/models/constraints.txt b/docs/ref/models/constraints.txt index c1f140c265..897c122f05 100644 --- a/docs/ref/models/constraints.txt +++ b/docs/ref/models/constraints.txt @@ -43,10 +43,6 @@ option. ``constraint_sql()``, ``create_sql()``, ``remove_sql()`` and ``validate()`` methods. - .. deprecated:: 5.0 - - Support for passing positional arguments is deprecated. - All constraints have the following parameters in common: ``name`` diff --git a/docs/releases/6.0.txt b/docs/releases/6.0.txt index fe54d371b7..87ac8de60f 100644 --- a/docs/releases/6.0.txt +++ b/docs/releases/6.0.txt @@ -255,7 +255,7 @@ in Django 6.0. See :ref:`deprecated-features-5.0` for details on these changes, including how to remove usage of these features. -* ... +* Support for passing positional arguments to ``BaseConstraint`` is removed. See :ref:`deprecated-features-5.1` for details on these changes, including how to remove usage of these features. diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py index 9047710098..4cf5a748a7 100644 --- a/tests/constraints/tests.py +++ b/tests/constraints/tests.py @@ -103,11 +103,6 @@ class BaseConstraintTests(SimpleTestCase): }, ) - def test_deprecation(self): - msg = "Passing positional arguments to BaseConstraint is deprecated." - with self.assertRaisesMessage(RemovedInDjango60Warning, msg): - BaseConstraint("name", "violation error message") - def test_name_required(self): msg = ( "BaseConstraint.__init__() missing 1 required keyword-only argument: 'name'" @@ -115,11 +110,6 @@ class BaseConstraintTests(SimpleTestCase): with self.assertRaisesMessage(TypeError, msg): BaseConstraint() - @ignore_warnings(category=RemovedInDjango60Warning) - def test_positional_arguments(self): - c = BaseConstraint("name", "custom %(name)s message") - self.assertEqual(c.get_violation_error_message(), "custom name message") - class CheckConstraintTests(TestCase): def test_eq(self):