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

fbv failes with Exception: methods ['serializer'] in class docstring are not in view methods [u'OPTIONS', u'GET'] #153

Closed
f3r3nc opened this issue Nov 23, 2014 · 12 comments

Comments

@f3r3nc
Copy link

f3r3nc commented Nov 23, 2014

The following documentation raised the error.

"""
    ---
    serializer: MySerializer
"""

Had to change docgenerator.py:42 from:

        if str(callback) == \
                "<class 'rest_framework.decorators.WrappedAPIView'>":

to

        if str(callback).startswith("<class 'rest_framework.decorators."):

This also reproduces for the example project and doesn't seem to be tested.

@ariovistus
Copy link
Contributor

I think it wants you to format your docstring like

"""
    ---
    GET:
          serializer: MySerializer
    OPTIONS:
          serializer: MySerializer
"""

though this really needs to be improved.

@f3r3nc
Copy link
Author

f3r3nc commented Nov 23, 2014

Unfortunately, the problem is still there with this kind of docstring.
The get_introspector returns APIViewIntrospector instead of WrappedAPIViewIntrospector for the fbv.
The proposed code above does fix this.
The docstring however doesn't make any change to it.

@ariovistus
Copy link
Contributor

rats. can you get me a complete example so I can duplicate or a failing test case that covers this?

@f3r3nc
Copy link
Author

f3r3nc commented Nov 24, 2014

Actually, the cigar example does have a test case for this!
Running manage test will give the same error.
I am using:

Django==1.6.6
djangorestframework==2.3.13

@ariovistus
Copy link
Contributor

can't duplicate. what version of python?

@f3r3nc
Copy link
Author

f3r3nc commented Nov 25, 2014

it happens both on Python 2.7.6 and Python 2.7.8

@ariovistus
Copy link
Contributor

hmm. I seem to be using python 2.7.5. If you install tox and add to tox.ini

[testenv:py2.7-django1.6-drf2.3.13]
basepython = python2.7
deps =  Django==1.6.6
        PyYAML==3.10
        argh==0.23.2
        argparse==1.2.1
        coverage==3.6
        django-nose==1.2
        djangorestframework==2.3.13
        nose==1.3.0

and run

tox -e py2.7-django1.6-drf2.3.13

does it fail? or do any of the other environments fail?

@f3r3nc
Copy link
Author

f3r3nc commented Nov 26, 2014

The test doesn't seem to cover the docgeneroator.get_operations function.
However, the tox fails with a non-related testcase:

======================================================================
FAIL: test_fbv_markdown (rest_framework_swagger.tests.YAMLDocstringParserTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../django-rest-swagger/rest_framework_swagger/tests.py", line 1450, in test_fbv_markdown
    self.assertEqual(notes, "<p>Slimy <em>toads</em></p>")
AssertionError: u'Slimy *toads*' != '<p>Slimy <em>toads</em></p>'

Have you tried running: python mange.py test in the tests/cigar_example project?

@ariovistus
Copy link
Contributor

whoops. add Markdown==2.5.1 to that list. running python manage.py test in tests/cigar_example passes for me, and it ought to be included in the test suite anyways.

what does str(callback) return for you?

@f3r3nc
Copy link
Author

f3r3nc commented Nov 27, 2014

"<class 'rest_framework.decorators." + function_name
for the function that was decorated by api_view

@ariovistus
Copy link
Contributor

As if str is returning something different for you than it is for me. I know callback.name returns the name of the function, not WrappedAPIView, so I guess the code in question is pretty tenuous, but I still want to know why this is happening. What platform are you on?

ariovistus pushed a commit that referenced this issue Nov 27, 2014
@f3r3nc
Copy link
Author

f3r3nc commented Nov 28, 2014

It's the same on Mac 10.9.5 and Debian Linux 7.6
thanks for the fix!

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

No branches or pull requests

2 participants