Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 of 6 tasks
stephenfin opened this issue Oct 19, 2018 · 5 comments
Closed
5 of 6 tasks

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

stephenfin opened this issue Oct 19, 2018 · 5 comments
Milestone

Comments

@stephenfin
Copy link
Contributor

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.

stephenfin added a commit to stephenfin/django-rest-framework that referenced this issue Oct 20, 2018
We were mistakenly importing the 'urlparse' function from the Python 2
'urlparse' module, as opposed to the module itself. Correct this.

Signed-off-by: Stephen Finucane <[email protected]>
Closes: encode#6261
@stephenfin
Copy link
Contributor Author

I've part of this fixed with #6262 but there are more issues here.

$ DJANGO_SETTINGS_MODULE=patchwork.settings.dev python manage.py generateschema --format openapi
!!python/unicode 'info':                                                           
  !!python/unicode 'description': !!python/unicode ''                   
  !!python/unicode 'title': !!python/unicode ''                            
  !!python/unicode 'version': !!python/unicode ''      
!!python/unicode 'openapi': !!python/unicode '3.0.0'                               
!!python/unicode 'paths':                                   
  /api/{var}:                                                                      
    !!python/unicode 'get':                                 
      !!python/unicode 'operationId': !!python/unicode 'api_read'          
      !!python/unicode 'parameters':                                               
      - !!python/unicode 'in': path                         
        !!python/unicode 'name': var                                               
        !!python/unicode 'required': true                             
        !!python/unicode 'schema':                                                 
          !!python/unicode 'description': ''                        
          !!python/unicode 'title': !!python/tuple
          - ''
          !!python/unicode 'type': !!python/unicode 'string'
      !!python/unicode 'tags':
      - api
      ...

@carltongibson carltongibson added this to the 3.9.1 Release milestone Oct 24, 2018
@carltongibson
Copy link
Collaborator

carltongibson commented Oct 24, 2018

Given #6230 (which'll be 3.10) I'm wondering how much effort we want to exert here. (We may just want to say "Oh well...")

Milestoned for 3.9.1, since it's that or not at all.

@valberg
Copy link

valberg commented Nov 2, 2018

I'm running into this issue currently, and would like to voice the opinion that while 1.11 is LTS things like this should work as intended.

@carltongibson
Copy link
Collaborator

I've part of this fixed with #6262 but there are more issues here.

@stephenfin Any update on the remaining issues?

@stephenfin
Copy link
Contributor Author

@stephenfin Any update on the remaining issues?

I hadn't prioritized them as it didn't seem worth the effort, per #6261 (comment). I can pick it back up though. I think #6262 is ready to go as-is.

tomchristie pushed a commit that referenced this issue Jan 8, 2019
* compat: (py2) urlparse = urllib.parse (py3)

We were mistakenly importing the 'urlparse' function from the Python 2
'urlparse' module, as opposed to the module itself. Correct this.

Signed-off-by: Stephen Finucane <[email protected]>
Closes: #6261

* compat: Remove 'compat.urlparse'

We can just use Django's vendored six library, like we do everywhere
else.

Signed-off-by: Stephen Finucane <[email protected]>
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this issue Nov 17, 2020
* compat: (py2) urlparse = urllib.parse (py3)

We were mistakenly importing the 'urlparse' function from the Python 2
'urlparse' module, as opposed to the module itself. Correct this.

Signed-off-by: Stephen Finucane <[email protected]>
Closes: encode#6261

* compat: Remove 'compat.urlparse'

We can just use Django's vendored six library, like we do everywhere
else.

Signed-off-by: Stephen Finucane <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants