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

session insert record error #70

Closed
tonyshare opened this issue Mar 6, 2019 · 2 comments
Closed

session insert record error #70

tonyshare opened this issue Mar 6, 2019 · 2 comments

Comments

@tonyshare
Copy link

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
Copy link
Author

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

yield as_future(session.commit)

@siddhantgoel
Copy link
Owner

siddhantgoel commented Mar 21, 2019

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

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

2 participants