Allow schema = None
. Deprecate exclude_from_schema
by carltongibson · Pull Request #5422 · encode/django-rest-framework (original) (raw)
The PR allows setting schema = None
to exclude APIView subclasses from schema generation.
For function based views use @schema(None)
.
It deprecates exclude_from_schema
on APIView and the exclude_from_schema
argument to api_view
.
WrappedAPIView.exclude_from_schema = exclude_from_schema |
---|
if exclude_from_schema: |
warnings.warn( |
"The `exclude_from_schema` argument to `api_view` is deprecated. " |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"is pending deprecation"
assert should_include == expected |
def test_deprecations(self): |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rpkilby I'm getting console noise in the test run from this. (Well from the call site but...)
tests/test_schemas.py ............/Users/carlton/Documents/Django-Stack/django-rest-framework/rest_framework/decorators.py:83: PendingDeprecationWarning: The `exclude_from_schema` argument to `api_view` is deprecated. Use the `schema` decorator instead, passing `None`.
PendingDeprecationWarning
/Users/carlton/Documents/Django-Stack/django-rest-framework/rest_framework/schemas/generators.py:156: PendingDeprecationWarning: OldFashjonedExcludedView. The `APIView.exclude_from_schema` is deprecated. Set `schema = None` instead
warnings.warn(msg, PendingDeprecationWarning)
....
tests/test_serializer.py .........................................
Can you advise on the best way to keep that quiet? Ta!
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need to test this. Don't believe that we've done so when deprecating other bits of API.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warnings.warn( |
---|
"The built in 'rest_framework.filters.FilterSet' is deprecated. " |
"You should use 'django_filters.rest_framework.FilterSet' instead.", |
DeprecationWarning, stacklevel=2 |
) |
and
@unittest.skipUnless(django_filters, 'django-filter not installed') |
---|
def test_backend_deprecation(self): |
with warnings.catch_warnings(record=True) as w: |
warnings.simplefilter("always") |
view = FilterFieldsRootView.as_view() |
request = factory.get('/') |
response = view(request).render() |
assert response.status_code == status.HTTP_200_OK |
assert response.data == self.data |
self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) |
self.assertIn("'rest_framework.filters.DjangoFilterBackend' is deprecated.", str(w[-1].message)) |
It's something @rpkilby always puts in. I thought, Why not? 🙂
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rpkilby OK. Thanks. I read that too but was still getting the noise...
- I went with
pytest.warns(PendingDeprecationWarning)
because (for me)pytest.deprecated_call()
failed withDID NOT WARN
. No ideas why that wasn't working. - Despite the noise locally for me, this is not appearing in the travis run — so it must be my local setup.
(There is plenty of noise from py.test in travis but I assume that'll disappear with time.)
Lets call this done. Thanks for the input!
@tomchristie I think we're good to go.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite the noise locally for me, this is not appearing in the travis run — so it must be my local setup.
No noise when running the tests on my machine, so that would make sense.
Milestoned for 3.6.5. I'll convert that to 3.7 next week and begin putting together a release.
Ryan P Kilby and others added 2 commits