graphql-python / graphql-server

This is the core package for using GraphQL in a custom server easily
MIT License
120 stars 72 forks source link

BC change in `json_encode()` breaks flask-graphql #31

Closed kaime closed 4 years ago

kaime commented 4 years ago

I'm using flask-graphql 2.0.1 My builds broke today without changing a single package version. This is the error I'm getting from the GraphQL server:

[2019-12-06 12:45:23,292] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.7/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/flask_graphql/graphqlview.py", line 101, in dispatch_request
    encode=partial(self.encode, pretty=pretty)
  File "/usr/local/lib/python3.7/site-packages/graphql_server/__init__.py", line 172, in encode_execution_results
    return ServerResponse((encode or json_encode)(result), status_code)
TypeError: json_encode() got an unexpected keyword argument 'pretty'

Apparently, flask-graphql, which depends on graphql-server-core>=1.1,<2, relies on the json_encode() method exported by graphql-server-core, and it assumes it accepts a pretty argument. But this argument dissapeared in version 1.1.2 of graphql-server-core (although it's still present on the function docstring): https://github.com/graphql-python/graphql-server-core/commit/52b4efc12b7b207465941de136c454e501847917

Cito commented 4 years ago

Thanks for reporting. Already fixed and released on PyPI as version 1.1.3.

For future compatibility, I recommend using either json_encode without pretty argument or json_encode_pretty.