Raise framework-specific deprecation warnings

- Use `RemovedInDRF313Warning` instead of DeprecationWarning
- Update to follow deprecation policy
This commit is contained in:
Ryan P Kilby 2019-12-04 16:38:26 -08:00
parent 90eaf51839
commit 988f5b2034

View File

@ -30,7 +30,7 @@ from django.utils.timezone import utc
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from pytz.exceptions import InvalidTimeError from pytz.exceptions import InvalidTimeError
from rest_framework import ISO_8601 from rest_framework import ISO_8601, RemovedInDRF313Warning
from rest_framework.compat import ProhibitNullCharactersValidator from rest_framework.compat import ProhibitNullCharactersValidator
from rest_framework.exceptions import ErrorDetail, ValidationError from rest_framework.exceptions import ErrorDetail, ValidationError
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
@ -263,10 +263,10 @@ class CreateOnlyDefault:
if hasattr(self.default, 'set_context'): if hasattr(self.default, 'set_context'):
warnings.warn( warnings.warn(
"Method `set_context` on defaults is deprecated and will " "Method `set_context` on defaults is deprecated and will "
"no longer be called starting with 3.12. Instead set " "no longer be called starting with 3.13. Instead set "
"`requires_context = True` on the class, and accept the " "`requires_context = True` on the class, and accept the "
"context as an additional argument.", "context as an additional argument.",
DeprecationWarning, stacklevel=2 RemovedInDRF313Warning, stacklevel=2
) )
self.default.set_context(self) self.default.set_context(self)
@ -502,10 +502,10 @@ class Field:
if hasattr(self.default, 'set_context'): if hasattr(self.default, 'set_context'):
warnings.warn( warnings.warn(
"Method `set_context` on defaults is deprecated and will " "Method `set_context` on defaults is deprecated and will "
"no longer be called starting with 3.12. Instead set " "no longer be called starting with 3.13. Instead set "
"`requires_context = True` on the class, and accept the " "`requires_context = True` on the class, and accept the "
"context as an additional argument.", "context as an additional argument.",
DeprecationWarning, stacklevel=2 RemovedInDRF313Warning, stacklevel=2
) )
self.default.set_context(self) self.default.set_context(self)
@ -576,10 +576,10 @@ class Field:
if hasattr(validator, 'set_context'): if hasattr(validator, 'set_context'):
warnings.warn( warnings.warn(
"Method `set_context` on validators is deprecated and will " "Method `set_context` on validators is deprecated and will "
"no longer be called starting with 3.12. Instead set " "no longer be called starting with 3.13. Instead set "
"`requires_context = True` on the class, and accept the " "`requires_context = True` on the class, and accept the "
"context as an additional argument.", "context as an additional argument.",
DeprecationWarning, stacklevel=2 RemovedInDRF313Warning, stacklevel=2
) )
validator.set_context(self) validator.set_context(self)