Skip to content

Commit

Permalink
Store self.action='metadata' for OPTIONS requests on viewsets. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Jul 14, 2015
1 parent 11e3cfb commit 538ffaf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rest_framework/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ 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)

Expand Down

4 comments on commit 538ffaf

@source-creator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting the following error, with the code I downloaded today (20150715). I wasn't getting this error on the 10th.
This happens when I try and get an item, eg: /api/model/id/

File "xxx/lib/python3.4/site-packages/rest_framework/viewsets.py", line 79, in view
  handler = getattr(self, action)
AttributeError: 'xxxViewSet' object has no attribute 'metadata'

@tomchristie
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay thanks for the report - will look into that.

@loic
Copy link
Contributor

@loic loic commented on 538ffaf Jul 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, viewset works the first time, then any subsequent refresh trigger this exception, haven't had time to investigate.

@tomchristie
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking against #3115

Please sign in to comment.