【问题标题】:Flask, SQLAlchemy error (invalid transaction)Flask,SQLAlchemy 错误(无效事务)
【发布时间】:2017-08-10 07:48:16
【问题描述】:

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

异常消息:在滚动无效事务之前无法重新连接 返回(原始原因:InvalidRequestError: Can't reconnect until 无效事务回滚) 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 作为 a_auth2_user_plain_password, a_auth2_user.legacy_password 作为 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' [不可变字典({})]

奇怪的是它“有时”会返回这个错误!有时它工作正常。 是不是内存问题?!我该如何解决?

【问题讨论】:

    标签: python flask sqlalchemy


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-09-16
      • 2021-02-06
      • 2016-02-03
      • 2013-08-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2021-02-09
      相关资源
      最近更新 更多