diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 45c8bbefd8..72bfe614d9 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -30,9 +30,7 @@ from django.utils.translation import gettext_lazy as _ from pytz.exceptions import InvalidTimeError -from rest_framework import ( - ISO_8601, RemovedInDRF313Warning, RemovedInDRF314Warning -) +from rest_framework import ISO_8601, RemovedInDRF314Warning from rest_framework.exceptions import ErrorDetail, ValidationError from rest_framework.settings import api_settings from rest_framework.utils import html, humanize_datetime, json, representation @@ -265,16 +263,6 @@ def __call__(self, serializer_field): if is_update: raise SkipField() if callable(self.default): - if hasattr(self.default, 'set_context'): - warnings.warn( - "Method `set_context` on defaults is deprecated and will " - "no longer be called starting with 3.13. Instead set " - "`requires_context = True` on the class, and accept the " - "context as an additional argument.", - RemovedInDRF313Warning, stacklevel=2 - ) - self.default.set_context(self) - if getattr(self.default, 'requires_context', False): return self.default(serializer_field) else: @@ -504,16 +492,6 @@ def get_default(self): # No default, or this is a partial update. raise SkipField() if callable(self.default): - if hasattr(self.default, 'set_context'): - warnings.warn( - "Method `set_context` on defaults is deprecated and will " - "no longer be called starting with 3.13. Instead set " - "`requires_context = True` on the class, and accept the " - "context as an additional argument.", - RemovedInDRF313Warning, stacklevel=2 - ) - self.default.set_context(self) - if getattr(self.default, 'requires_context', False): return self.default(self) else: @@ -578,16 +556,6 @@ def run_validators(self, value): """ errors = [] for validator in self.validators: - if hasattr(validator, 'set_context'): - warnings.warn( - "Method `set_context` on validators is deprecated and will " - "no longer be called starting with 3.13. Instead set " - "`requires_context = True` on the class, and accept the " - "context as an additional argument.", - RemovedInDRF313Warning, stacklevel=2 - ) - validator.set_context(self) - try: if getattr(validator, 'requires_context', False): validator(value, self) diff --git a/tests/test_fields.py b/tests/test_fields.py index cbec79119a..56276e6ffc 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -566,7 +566,7 @@ def test_create_only_default_is_not_provided_on_update(self): def test_create_only_default_callable_sets_context(self): """ - CreateOnlyDefault instances with a callable default should set_context + CreateOnlyDefault instances with a callable default should set context on the callable if possible """ class TestCallableDefault: