jfinkels / flask-restless

NO LONGER MAINTAINED - A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.
https://flask-restless.readthedocs.io
GNU Affero General Public License v3.0
1.02k stars 301 forks source link

PATCH incorrectly checks content_type in certain situations #684

Open artagel opened 6 years ago

artagel commented 6 years ago

When running a PATCH operation, if the content type header isn't set, then the content_type variable is set to None. When this occurs, you traceback on evaluating startswith on None Line 1499 of views.py

        content_type = request.headers.get('Content-Type', None)
        content_is_json = content_type.startswith('application/json')

Traceback

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.5/dist-packages/flask_restless/views.py", line 157, in decorator
    return func(*args, **kw)
  File "/usr/local/lib/python3.5/dist-packages/mimerender.py", line 244, in wrapper
    result = target(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/flask/views.py", line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/flask/views.py", line 149, in dispatch_request
    return meth(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/flask_restless/views.py", line 189, in wrapped
    return func(*args, **kw)
  File "/usr/local/lib/python3.5/dist-packages/flask_restless/views.py", line 1499, in patch
    content_is_json = content_type.startswith('application/json')
AttributeError: 'NoneType' object has no attribute 'startswith'
artagel commented 6 years ago

Version 0.17.0