tornado
tornado copied to clipboard
AttributeError: '_NullFuture' object has no attribute 'add_done_callback'
Hi,
I deployed tornado web with these versions.
Ubuntu 18.04 Python 3.11.4 Tornado 6.3.2
I couldn't solve the issue as you see below.
Currently, we use Tornado 5.0.2 and Python 3.6.9 versions. We decided upgrade python to 3.11.4 and all packages. I tried versions of tornado from 5.0 to 6.3.2, but couldn't solve.
E 230620 15:07:01 http1connection:67] Uncaught exception Traceback (most recent call last): File "/home/shippn/.pyenv/versions/venv/lib/python3.11/site-packages/tornado/http1connection.py", line 276, in _read_message delegate.finish() File "/home/shippn/.pyenv/versions/venv/lib/python3.11/site-packages/tornado/routing.py", line 268, in finish self.delegate.finish() File "/home/shippn/.pyenv/versions/venv/lib/python3.11/site-packages/tornado/web.py", line 2395, in finish self.execute() File "/home/shippn/.pyenv/versions/venv/lib/python3.11/site-packages/tornado/web.py", line 2434, in execute fut.add_done_callback(lambda f: f.result()) ^^^^^^^^^^^^^^^^^^^^^ AttributeError: '_NullFuture' object has no attribute 'add_done_callback'
Hmm, I've never seen that and I'm not quite sure how you'd get there. Are you overriding RequestHandler._execute somehow?
What you've written is unnecessarily complicated and, not to mention, results in error.
Instead of patching RequestHandler._execute method, you should instead perform the authentication checks in the RequestHandler.prepare method of the base class.
Hi, Thank you for comment, the codes are not solid I know that, I am new in the project, I wanna figure out the issue, can you refactor any part for me?
On the file provided by @dryalcinmehmet, there is an options method decorated with tornado.gen.coroutine, no yields just returns. Should that the be source of the _NullFuture?
there is an options method decorated with tornado.gen.coroutine, no yields just returns. Should that the be source of the _NullFuture?
No, tornado.gen.coroutine should still use a real future in this case.
I don't see exactly where the _NullFuture is coming from, but this interceptor decorator is problematic in a number of ways. Wrapping _execute without actually calling the underlying _execute method is probably going to break something, as is discarding the return value of the real _execute method.
I agree with @bhch that you should not be overriding _execute here and should do your auth checks in prepare() instead. We previously kinda-supported overriding _execute because prepare couldn't be asynchronous, but now that we support coroutines in prepare there's no reason to override _execute any more and you should stay away from it.