siddhantgoel / tornado-sqlalchemy

SQLAlchemy support for Tornado
https://tornado-sqlalchemy.readthedocs.io/en/latest/
MIT License
125 stars 21 forks source link

session insert record error #70

Closed tonyshare closed 5 years ago

tonyshare commented 5 years ago

when insert a record to database i got "'NoneType' object is not callable" ` import tornado.web from tornado.gen import coroutine from tornado_sqlalchemy import as_future from database.tables import *

class UploadFileHandler(BaseHandler):

@coroutine def post(self): _file = self.request.files['upload'][0] _filename = _file["filename"].split(".")[0] _extension = _file["filename"].split(".")[1] _mobile = '12345678901' upload_file = UploadFile(mobile=_mobile, body=_file['body'], filename=_filename, extension=_extension) with self.make_session() as session: session.add(upload_file) yield as_future(session.commit()) ` and the error log is

File "/usr/local/lib/python3.5/dist-packages/tornado/web.py", line 1592, in _execute result = yield result File "/usr/local/lib/python3.5/dist-packages/tornado/gen.py", line 1133, in run value = future.result() File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result raise self._exception File "/usr/local/lib/python3.5/dist-packages/tornado/gen.py", line 1141, in run yielded = self.gen.throw(exc_info) File "/srv/www/api/upload_file.py", line 20, in post yield as_future(session.commit()) File "/usr/local/lib/python3.5/dist-packages/tornado/gen.py", line 1133, in run value = future.result() File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result raise self._exception File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run result = self.fn(self.args, **self.kwargs) TypeError: 'NoneType' object is not callable

tonyshare commented 5 years ago

i have solved the problem, just remove the () after commit

yield as_future(session.commit)

siddhantgoel commented 5 years ago

session.commit doesn't return a query object. as_future only works on query objects, hence the exception you received.