2017-08-10 132 views
0

我有一個燒瓶網站。有時在某些請求上它返回此錯誤:燒瓶,SQLAlchemy錯誤(無效的事務)

Exception message: Can't reconnect until invalid transaction is rolled back (original cause: InvalidRequestError: Can't reconnect until invalid transaction is rolled back) u'SELECT a_auth2_user.id AS a_auth2_user_id, a_auth2_user.username AS a_auth2_user_username, a_auth2_user.fullname 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 \nFROM a_auth2_user \nWHERE a_auth2_user.id = %s \n LIMIT %s' [immutabledict({})]

奇怪的是,它返回此錯誤「有時」!有時它工作正常。 這是像內存問題?我該如何解決它?

回答

0

因爲您之前的提交可能會有一些異常,所以如果有任何無效的事務,您應該將會話roolbak。

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