Flask,SQLAlchemy 错误(无效事务)



我有一个烧瓶网站。有时在某些请求上它会返回此错误:

异常消息:在滚动无效事务之前无法重新连接 返回(原始原因:无效请求错误:无法重新连接,直到 无效事务回滚( u'SELECT a_auth2_user.id AS a_auth2_user_id,a_auth2_user.用户名作为a_auth2_user_username, a_auth2_user.全名 AS a_auth2_user_fullname,a_auth2_user.email AS a_auth2_user_email,a_auth2_user.password AS a_auth2_user_password, a_auth2_user.plain_password AS a_auth2_user_plain_password, a_auth2_user.legacy_password AS a_auth2_user_legacy_password, a_auth2_user.active AS a_auth2_user_active, a_auth2_user.is_admin AS a_auth2_user_is_admin,a_auth2_user.phone AS a_auth2_user_phone, a_auth2_user.last_activity AS a_auth2_user_last_activity FROM a_auth2_user 其中 a_auth2_user.id = %s 限制 %s' [不可变字典({}(]

奇怪的是,它"有时"返回此错误!有时它工作正常。 是不是内存问题之类的东西?!我该如何解决它?

因为你之前的提交可能会有一些异常,所以如果有任何无效的事务,你应该对会话进行roolbak。

try:
transaction.commit()
except Exception, e:
session.rollback()