Update deprecations

This commit is contained in:
Carlton Gibson 2018-03-26 11:42:55 +02:00
parent cfa942ffc1
commit d4acf952d5
5 changed files with 32 additions and 11 deletions

View File

@ -153,7 +153,7 @@ See the pagination documentation for further guidance on [setting the pagination
---
**This setting is pending deprecation.**
**This setting has been removed.**
See the pagination documentation for further guidance on [setting the pagination style](pagination.md#modifying-the-pagination-style).

View File

@ -56,7 +56,26 @@ Alternatively you may override `save()` or `create()` or `update()` on the seria
## Deprecations
TODO
### `action` decorator replaces `list_route` and `detail_route`
[#5705][gh5705] `list_route` and `detail_route` have been merge into a single `action` decorator. This improves viewset action introspection, and will allow extra actions to be displayed in the Browsable API in future versions.
Both `list_route` and `detail_route` are now pending deprecation. They will be deprecated in 3.9 and removed entirely
in 3.10.
The new `action` decorator takes a boolean `detail` argument.
* Replace `detail_route` uses with `@action(detail=True)`.
* Replace `list_route` uses with `@action(detail=False)`.
### `exclude_from_schema`
Both `APIView.exclude_from_schema` and the `exclude_from_schema` argument to the `@api_view` decorator are now deprecated. They will be removed entirely in 3.9.
For `APIView` you should instead set a `schema = None` attribute on the view class.
For function based views the `@schema` decorator can be used to exclude the view from the schema, by using `@schema(None)`.
---
@ -72,3 +91,5 @@ TODO
[funding]: funding.md
[gh5886]: https://github.com/encode/django-rest-framework/issues/5886
[gh5705]: https://github.com/encode/django-rest-framework/issues/5705

View File

@ -78,9 +78,9 @@ def api_view(http_method_names=None, exclude_from_schema=False):
if exclude_from_schema:
warnings.warn(
"The `exclude_from_schema` argument to `api_view` is pending deprecation. "
"The `exclude_from_schema` argument to `api_view` is deprecated. "
"Use the `schema` decorator instead, passing `None`.",
PendingDeprecationWarning
DeprecationWarning
)
WrappedAPIView.exclude_from_schema = exclude_from_schema

View File

@ -208,10 +208,10 @@ class EndpointEnumerator(object):
return False # Ignore anything except REST framework views.
if hasattr(callback.cls, 'exclude_from_schema'):
fmt = ("The `{}.exclude_from_schema` attribute is pending deprecation. "
fmt = ("The `{}.exclude_from_schema` attribute is deprecated. "
"Set `schema = None` instead.")
msg = fmt.format(callback.cls.__name__)
warnings.warn(msg, PendingDeprecationWarning)
warnings.warn(msg, DeprecationWarning)
if getattr(callback.cls, 'exclude_from_schema', False):
return False

View File

@ -871,15 +871,15 @@ class SchemaGenerationExclusionTests(TestCase):
assert should_include == expected
def test_deprecations(self):
with pytest.warns(PendingDeprecationWarning) as record:
with pytest.warns(DeprecationWarning) as record:
@api_view(["GET"], exclude_from_schema=True)
def view(request):
pass
assert len(record) == 1
assert str(record[0].message) == (
"The `exclude_from_schema` argument to `api_view` is pending "
"deprecation. Use the `schema` decorator instead, passing `None`."
"The `exclude_from_schema` argument to `api_view` is deprecated. "
"Use the `schema` decorator instead, passing `None`."
)
class OldFashionedExcludedView(APIView):
@ -893,13 +893,13 @@ class SchemaGenerationExclusionTests(TestCase):
]
inspector = EndpointEnumerator(patterns)
with pytest.warns(PendingDeprecationWarning) as record:
with pytest.warns(DeprecationWarning) as record:
inspector.get_api_endpoints()
assert len(record) == 1
assert str(record[0].message) == (
"The `OldFashionedExcludedView.exclude_from_schema` attribute is "
"pending deprecation. Set `schema = None` instead."
"deprecated. Set `schema = None` instead."
)