graphql-python / graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
http://docs.graphene-python.org/projects/django/en/latest/
MIT License
4.31k stars 769 forks source link

TypeError: Object of type OperationType is not JSON serializable when there's an Exception #1383

Open sithembiso opened 1 year ago

sithembiso commented 1 year ago

My code has not changed, I simply upgraded Graphene (graphene-python, graphene-django)

platform     | Traceback (most recent call last):
platform     |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
platform     |     response = get_response(request)
platform     |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
platform     |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
platform     |   File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
platform     |     return view_func(*args, **kwargs)
platform     |   File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
platform     |     return self.dispatch(request, *args, **kwargs)
platform     |   File "/usr/local/lib/python3.9/site-packages/django/utils/decorators.py", line 43, in _wrapper
platform     |     return bound_method(*args, **kwargs)
platform     |   File "/usr/local/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
platform     |     response = view_func(request, *args, **kwargs)
platform     |   File "/usr/local/lib/python3.9/site-packages/graphene_django/views.py", line 179, in dispatch
platform     |     result, status_code = self.get_response(request, data, show_graphiql)
platform     |   File "/usr/local/lib/python3.9/site-packages/graphene_django/views.py", line 224, in get_response
platform     |     result = self.json_encode(request, response, pretty=show_graphiql)
platform     |   File "/usr/local/lib/python3.9/site-packages/graphene_django/views.py", line 235, in json_encode
platform     |     return json.dumps(d, separators=(",", ":"))
platform     |   File "/usr/local/lib/python3.9/json/__init__.py", line 234, in dumps
platform     |     return cls(
platform     |   File "/usr/local/lib/python3.9/json/encoder.py", line 199, in encode
platform     |     chunks = self.iterencode(o, _one_shot=True)
platform     |   File "/usr/local/lib/python3.9/json/encoder.py", line 257, in iterencode
platform     |     return _iterencode(o, 0)
platform     |   File "/usr/local/lib/python3.9/json/encoder.py", line 179, in default
platform     |     raise TypeError(f'Object of type {o.__class__.__name__} '
platform     | TypeError: Object of type OperationType is not JSON serializable

Everything was working fine before, until I upgraded to these versions:

Django==3.2.16
...
graphene==3.2.1
graphene-django==3.0.0
graphene-file-upload==1.3.0
graphql-core==3.2.3
graphql-relay==3.2.0
...
EverWinter23 commented 1 year ago

@sithembiso could you share a code snippet to reproduce this issue?