Skip to content

'generateschema' doesn't work with Python 2 #6261

Closed
@stephenfin

Description

@stephenfin

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

Run python manage.py generateschema on Python 2.

Expected behavior

It should run.

Actual behavior

Python 2.

$ docker-compose run --rm web python manage.py generateschema --format openapi                                                                                                                                    
Starting patchwork_db_1 ... done                                                                                                                                          
/usr/local/lib/python2.7/dist-packages/django_filters/rest_framework/backends.py:93: UserWarning: <class 'patchwork.api.bundle.BundleDetail'> is not compatible with schema generation
  "{} is not compatible with schema generation".format(view.__class__)                                                                                            
/usr/local/lib/python2.7/dist-packages/django_filters/rest_framework/backends.py:93: UserWarning: <class 'patchwork.api.comment.CommentList'> is not compatible with schema generation
  "{} is not compatible with schema generation".format(view.__class__)                                                                                                  
Traceback (most recent call last):                                                                                                                          
  File "manage.py", line 11, in <module>                                                                                                                         
    execute_from_command_line(sys.argv)                                                                                                        
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 364, in execute_from_command_line                                    
    utility.execute()                                                                                         
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 356, in execute                                      
    self.fetch_command(subcommand).run_from_argv(self.argv)                                               
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 283, in run_from_argv                                                
    self.execute(*args, **cmd_options)                                                                                                                                                
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 330, in execute                                                          
    output = self.handle(*args, **options)                                                                                                                                            
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/management/commands/generateschema.py", line 31, in handle                                                       
    output = renderer.render(schema, renderer_context={})                                                                                                               
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/renderers.py", line 1036, in render                                                                   
    structure = self.get_structure(data)                                                                                                                                  
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/renderers.py", line 1022, in get_structure                                                                         
    'paths': self.get_paths(data)                                                                                                                     
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/renderers.py", line 1004, in get_paths                                                 
    path = urlparse.urlparse(link.url).path                                                                                                                 
AttributeError: 'function' object has no attribute 'urlparse' 

Python 3

$ docker-compose run --rm web python3 manage.py generateschema --format openapi                                                                                         
Starting patchwork_db_1 ... done                                                                                                                                                                                   
/usr/local/lib/python3.6/dist-packages/django_filters/rest_framework/backends.py:128: UserWarning: <class 'patchwork.api.bundle.BundleList'> is not compatible with schema generation   
  "{} is not compatible with schema generation".format(view.__class__)                                                                                                                                             
/usr/local/lib/python3.6/dist-packages/django_filters/rest_framework/backends.py:128: UserWarning: <class 'patchwork.api.bundle.BundleDetail'> is not compatible with schema generation
  "{} is not compatible with schema generation".format(view.__class__)                                                                                                                                            
/usr/local/lib/python3.6/dist-packages/django_filters/rest_framework/backends.py:128: UserWarning: <class 'patchwork.api.comment.CommentList'> is not compatible with schema generation
  "{} is not compatible with schema generation".format(view.__class__)                                                                                              
/usr/local/lib/python3.6/dist-packages/django_filters/rest_framework/backends.py:128: UserWarning: <class 'patchwork.api.check.CheckListCreate'> is not compatible with schema generation
  "{} is not compatible with schema generation".format(view.__class__)                                                                                    
/usr/local/lib/python3.6/dist-packages/django_filters/rest_framework/backends.py:128: UserWarning: <class 'patchwork.api.check.CheckDetail'> is not compatible with schema generation
  "{} is not compatible with schema generation".format(view.__class__)                                                                                                                                             
info:                                                                                                                                                           
  description: ''                                                                                                                                                                                                  
  title: ''                                                                                                                                                                 
  version: ''
  ...

Looks like a dodgy wrapper in rest_framework.compat.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions