SQLAlchemy()增加异常捕获后,正常提交数据会偶发性rollback


#1

SQLAlchemy()增加异常捕获后,正常提交数据会偶发性rollback。会导致入库失败。只是偶发性的,大部分时间段能提交成功。
代码:
mm_rs.m_name = request.form[‘m_name’]
mm_rs.create_time = request.form[‘create_time’]
mm_rs.f_type = request.form[‘f_type’]
mm_rs.repair_time = request.form[‘repair_time’]
mm_rs.recoder_u = request.form[‘recoder_u’]
mm_rs.rich_text = request.form[‘rich_text’]

db.session.add(mm_rs)
try:
    db.session.commit()
except:
    db.session.rollback()
db.session.close()

日志:
5月 13 17:51:58 ptyy.knownsec.com python3[15236]: 2019-05-13 17:51:58,858 INFO sqlalchemy.engine.base.Engine INSERT INTO m_rr (m_name, create_time, f_type, repair_time, recoder_u, rich_text) VALUES (%(m_n
5月 13 17:51:58 ptyy.knownsec.com python3[15236]: 2019-05-13 17:51:58,858 INFO sqlalchemy.engine.base.Engine {‘m_name’: ‘日本机房CN2-2’, ‘create_time’: ‘2019-05-13 17:00:25’, ‘f_type’: ‘访问超时’, 'repair
5月 13 17:51:58 ptyy.knownsec.com python3[15236]: 2019-05-13 17:51:58,902 INFO sqlalchemy.engine.base.Engine ROLLBACK
5月 13 17:51:58 ptyy.knownsec.com python3[15236]: 127.0.0.1 - - [13/May/2019 17:51:58] “POST /m_rr HTTP/1.0” 200 -
5月 13 17:51:59 ptyy.knownsec.com python3[15236]: 2019-05-13 17:51:59,910 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)