From 03270431edc8ce88938a2d8495fe125867807cca Mon Sep 17 00:00:00 2001 From: Mohamad Nour Chawich Date: Sun, 20 Mar 2016 21:46:37 +0100 Subject: [PATCH] Reorder initializing the view Determining the version and performing content negotiation should be done before ensuring the permission of the request. The reason is that these information can be used in handling the exceptions. For example different versions may return different error scheme. Also, the rendering class can be used to determine how to exception handler response should be rendered. --- rest_framework/views.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rest_framework/views.py b/rest_framework/views.py index 56e3c4e49..c13e74447 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -372,11 +372,6 @@ class APIView(View): """ self.format_kwarg = self.get_format_suffix(**kwargs) - # Ensure that the incoming request is permitted - self.perform_authentication(request) - self.check_permissions(request) - self.check_throttles(request) - # Perform content negotiation and store the accepted info on the request neg = self.perform_content_negotiation(request) request.accepted_renderer, request.accepted_media_type = neg @@ -385,6 +380,11 @@ class APIView(View): version, scheme = self.determine_version(request, *args, **kwargs) request.version, request.versioning_scheme = version, scheme + # Ensure that the incoming request is permitted + self.perform_authentication(request) + self.check_permissions(request) + self.check_throttles(request) + def finalize_response(self, request, response, *args, **kwargs): """ Returns the final response object.