From a9f1d99cb5c91aef29d4d9d7a8617b5ba18793cf Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 16 Jul 2015 10:08:22 +0100 Subject: [PATCH] Fix 'metadata' action on viewsets. Closes #3158. Closes #3157. Closes #3115. --- rest_framework/viewsets.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/rest_framework/viewsets.py b/rest_framework/viewsets.py index 819deb430f..05434b72ec 100644 --- a/rest_framework/viewsets.py +++ b/rest_framework/viewsets.py @@ -83,12 +83,6 @@ def view(request, *args, **kwargs): if hasattr(self, 'get') and not hasattr(self, 'head'): self.head = self.get - # Explicitly map `options` requests to an (implicit) action named - # 'metadata'. This action doesn't actually exist as a named method, - # because, unlike other methods, we always route to it. - if hasattr(self, 'options'): - self.action_map['options'] = 'metadata' - # And continue as usual return self.dispatch(request, *args, **kwargs) @@ -112,7 +106,14 @@ def initialize_request(self, request, *args, **kwargs): depending on the request method. """ request = super(ViewSetMixin, self).initialize_request(request, *args, **kwargs) - self.action = self.action_map.get(request.method.lower()) + method = request.method.lower() + if method == 'options': + # This is a special case as we always provide handling for the + # options method in the base `View` class. + # Unlike the other explicitly defined actions, 'metadata' is implict. + self.action = 'metadata' + else: + self.action = self.action_map.get(method) return request