Skip to content
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

Document that dispatch should not be used for detail route method name #5636

Closed
1 task
lampwins opened this issue Nov 29, 2017 · 3 comments
Closed
1 task

Comments

@lampwins
Copy link

lampwins commented Nov 29, 2017

Checklist

  • [ x ] I have verified that that issue exists against the master branch of Django REST framework.
  • [ x ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • [ x ] This is not a usage question. (Those should be directed to the discussion group instead.)
  • [ x ] This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • [ x ] I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

Create a simple ViewSet with a detail route with method name dispatch

class TestViewSet(ModelViewSet):
    queryset = Test.objects.all()
    serializer_class = serializers.TestSerializer
    filter_class = filters.TestFilter

    @detail_route(url_path='dispatch', methods=['post'])
    def dispatch(self, request, pk=None):

        return Response("hello", status=status.HTTP_200_ACCEPTED)

Expected behavior

Not really sure here as it is colliding with the dispatch method under the hood of DFR

Actual behavior

The DRF router exhibits very odd behavior but does not function in any useful manor. It looks like the base path for the ViewSet is lost so all requests result in a 404.

I am not entirely sure what is going on but I can speculate that the detail route method is overlapping with the detail route method of the base ViewSet class. After looking deeper into DRF I understand why this is probably happening and why it probably can't easily be fixed. However, I think it would be fair to document this to say that a detail route method name should not be named dispatch.

@tomchristie
Copy link
Member

Given that this applies to any method name in APIView, I don't see any obvious way of addressing this in the documentation, other than mentioning that ViewSets inherit from APIView (which we do).

One option might be for us to link to http://www.cdrf.co/ in both the views and the viewsets documentation, perhaps?

@tomchristie
Copy link
Member

@lampwins
Copy link
Author

Yeah, I understand why it has to be this way so anything that can enhance the documentation would be helpful IMHO. I am in favor of your proposition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants