Skip to content

DRF 3.10 deprecated decorators #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
n2ygk opened this issue Jun 7, 2019 · 4 comments
Closed

DRF 3.10 deprecated decorators #657

n2ygk opened this issue Jun 7, 2019 · 4 comments
Assignees
Labels

Comments

@n2ygk
Copy link
Contributor

n2ygk commented Jun 7, 2019

The drfmaster builds are currently failing due to a deprecation described in encode/django-rest-framework#6687:

@detail_route/@list_route (replaced by @action)

Here's a snippet showing the error:

____________________ ERROR collecting example/urls_test.py _____________________
ImportError while importing test module '/home/travis/build/django-json-api/django-rest-framework-json-api/example/urls_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
example/urls_test.py:4: in <module>
    from .api.resources.identity import GenericIdentity, Identity
example/api/resources/identity.py:4: in <module>
    from rest_framework.decorators import detail_route, list_route
E   ImportError: cannot import name 'detail_route' from 'rest_framework.decorators' (/home/travis/build/django-json-api/django-rest-framework-json-api/.tox/py37-df20-django22-drfmaster/lib/python3.7/site-packages/rest_framework/decorators.py)
@n2ygk n2ygk added the bug label Jun 7, 2019
@n2ygk
Copy link
Contributor Author

n2ygk commented Jun 7, 2019

Looks like a pretty easy fix. Set detail=True for detail, False for list:

def action(methods=None, detail=None, url_path=None, url_name=None, **kwargs):
    """
    Mark a ViewSet method as a routable action.

    Set the `detail` boolean to determine if this action should apply to
    instance/detail requests or collection/list requests.
    """

@n2ygk n2ygk self-assigned this Jun 7, 2019
@n2ygk
Copy link
Contributor Author

n2ygk commented Jun 7, 2019

Unfortunately the @action decorator is relatively new, so simply replacing it breaks with drf<=3.7

@n2ygk
Copy link
Contributor Author

n2ygk commented Jun 7, 2019

The workaround wasn't terrible though. PR coming.

@sliverc
Copy link
Member

sliverc commented Jul 5, 2019

This got fixed with #664

@sliverc sliverc closed this as completed Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants