graphene-django icon indicating copy to clipboard operation
graphene-django copied to clipboard

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

Open sithembiso opened this issue 3 years ago • 1 comments

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

  • What is the current behavior? Since upgrading to the latest versions (on Django 3.2.16), I have started getting the following errors when an exception is raised in my resolvers and mutations:
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
...
  • What is the expected behavior? I expected everything to work as it used to before since I didn't change application code.

  • What is the motivation / use case for changing the behavior? I was actually trying to get the latest version of the Graphiql GUI when I started. But then I noticed that my dependencies were very outdated.

  • Please tell us about your environment:

    • Version: 3.0.0
    • Platform: Python 3.10.9, macOS Ventura (Chip M1 Pro)

sithembiso avatar Jan 17 '23 06:01 sithembiso

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

EverWinter23 avatar Apr 25 '23 18:04 EverWinter23