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

async handler methods not supported (Tornado 6.x) #104

Open
ricogini opened this issue Oct 24, 2018 · 2 comments
Open

async handler methods not supported (Tornado 6.x) #104

ricogini opened this issue Oct 24, 2018 · 2 comments

Comments

@ricogini
Copy link

A serialization exception is thrown if a handler is async instead of decorated with @coroutine
Example:

class MyFailingHandler(APIHandler):

  @schema.validate(input_schema={'type': 'string'})
  async def post(self):
    self.set_status(201, "created")

Thrown error:

File "/home/.virtualenvs/annotation_tool/lib/python3.6/site-packages/tornado/web.py", line 1592, in _execute
    result = yield result
  File "/home/.virtualenvs/annotation_tool/lib/python3.6/site-packages/tornado/gen.py", line 1133, in run
    value = future.result()
  File "/home/.virtualenvs/annotation_tool/lib/python3.6/site-packages/tornado/gen.py", line 326, in wrapper
    yielded = next(result)
  File "/home/.virtualenvs/annotation_tool/lib/python3.6/site-packages/tornado_json/schema.py", line 193, in _wrapper
    self.success(output)
  File "/home/.virtualenvs/annotation_tool/lib/python3.6/site-packages/tornado_json/jsend.py", line 20, in success
    self.write({'status': 'success', 'data': data})
  File "/home/.virtualenvs/annotation_tool/lib/python3.6/site-packages/tornado/web.py", line 746, in write
    chunk = escape.json_encode(chunk)
  File "/home/.virtualenvs/annotation_tool/lib/python3.6/site-packages/tornado/escape.py", line 81, in json_encode
    return json.dumps(value).replace("</", "<\\/")
  File "/usr/lib/python3.6/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'coroutine' is not JSON serializable

Tested with python 3.6

@pletnes
Copy link

pletnes commented Apr 16, 2019

I got hit by the same on tornado 6.0.x and python 3.7.1.

@hfaran
Copy link
Owner

hfaran commented Apr 17, 2019

Hey folks, looks like this is a breaking change in Tornado 6.x. For the time being, I have created a new release (1.3.4) that pins a working set of dependencies so the project continues to behave as it has before.

I don't have time to look into updating Tornado-JSON to support Tornado 6.x at the moment, but I welcome PRs in case anyone is interested in adding support.

@hfaran hfaran changed the title async handler methods not supported async handler methods not supported (Tornado 6.x) Apr 17, 2019
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