Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

ViewSetIntrospector broken with DRF 2.4.3 #123

Closed
vil-s opened this issue Sep 23, 2014 · 5 comments
Closed

ViewSetIntrospector broken with DRF 2.4.3 #123

vil-s opened this issue Sep 23, 2014 · 5 comments

Comments

@vil-s
Copy link

vil-s commented Sep 23, 2014

DRF issue: encode/django-rest-framework#1893

Since DRF 2.4.3, the CSRF exemption is added in the APIView's (and by extension ViewSet's) as_view method and no longer in dispatch. (See encode/django-rest-framework#1706 and encode/django-rest-framework#1887).

What happens now is that ViewSetIntrospector._resolve_methods's self.pattern.callback is not the view, but the view wrapped in a csrf_exempt decorator.

@ydaniv
Copy link

ydaniv commented Sep 28, 2014

Alas! This is infact breaking all views. Any PR coming this way?

@tomchristie
Copy link
Contributor

Pinging @marcgibbons - what do you reckon the status of rest-swagger is these days - likely to come back to maintaining it anytime?

@t16n
Copy link

t16n commented Oct 8, 2014

hey joeatmatterport this seems to work for me thank you!

For Python v3:

    def _resolve_methods(self):
        callback = self.pattern.callback
        code_attr = '__code__'
        closure_attr = '__closure__'
        code = getattr(callback, code_attr)
        closure = getattr(callback, closure_attr)

        if code and getattr(code, 'co_name') == 'wrapped_view':
            # lets unwrap!
            view = getattr(closure[0], 'cell_contents')
            closure = getattr(view, closure_attr)
            code = getattr(view, code_attr)
            freevars = code.co_freevars

        elif code and getattr(code, 'co_name') == 'view':
            freevars = code.co_freevars
        else:
            raise RuntimeError(
                'Unable to use callback invalid closure/function specified.')

        return closure[freevars.index('actions')].cell_contents

@allardhoeve
Copy link

I fixed this by pulling #127, thanks!

@ariovistus
Copy link
Contributor

fixed in develop.

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

Successfully merging a pull request may close this issue.

6 participants