mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
Refs #34355 -- Removed support for positional arguments in BaseConstraint per deprecation timeline.
This commit is contained in:
parent
810edfd742
commit
b5a6c93a18
@ -25,19 +25,9 @@ class BaseConstraint:
|
|||||||
|
|
||||||
non_db_attrs = ("violation_error_code", "violation_error_message")
|
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__(
|
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
|
self.name = name
|
||||||
if violation_error_code is not None:
|
if violation_error_code is not None:
|
||||||
self.violation_error_code = violation_error_code
|
self.violation_error_code = violation_error_code
|
||||||
@ -45,17 +35,6 @@ class BaseConstraint:
|
|||||||
self.violation_error_message = violation_error_message
|
self.violation_error_message = violation_error_message
|
||||||
else:
|
else:
|
||||||
self.violation_error_message = self.default_violation_error_message
|
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
|
@property
|
||||||
def contains_expressions(self):
|
def contains_expressions(self):
|
||||||
|
@ -43,10 +43,6 @@ option.
|
|||||||
``constraint_sql()``, ``create_sql()``, ``remove_sql()`` and
|
``constraint_sql()``, ``create_sql()``, ``remove_sql()`` and
|
||||||
``validate()`` methods.
|
``validate()`` methods.
|
||||||
|
|
||||||
.. deprecated:: 5.0
|
|
||||||
|
|
||||||
Support for passing positional arguments is deprecated.
|
|
||||||
|
|
||||||
All constraints have the following parameters in common:
|
All constraints have the following parameters in common:
|
||||||
|
|
||||||
``name``
|
``name``
|
||||||
|
@ -255,7 +255,7 @@ in Django 6.0.
|
|||||||
See :ref:`deprecated-features-5.0` for details on these changes, including how
|
See :ref:`deprecated-features-5.0` for details on these changes, including how
|
||||||
to remove usage of these features.
|
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
|
See :ref:`deprecated-features-5.1` for details on these changes, including how
|
||||||
to remove usage of these features.
|
to remove usage of these features.
|
||||||
|
@ -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):
|
def test_name_required(self):
|
||||||
msg = (
|
msg = (
|
||||||
"BaseConstraint.__init__() missing 1 required keyword-only argument: 'name'"
|
"BaseConstraint.__init__() missing 1 required keyword-only argument: 'name'"
|
||||||
@ -115,11 +110,6 @@ class BaseConstraintTests(SimpleTestCase):
|
|||||||
with self.assertRaisesMessage(TypeError, msg):
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
BaseConstraint()
|
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):
|
class CheckConstraintTests(TestCase):
|
||||||
def test_eq(self):
|
def test_eq(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user