我有以下代码:
1 def normalize_and_save_phones():
2 not_normalized_records = Order.query.filter(
3 Order.formatted_phone.is_(None)).all()
. . . . . some code . . . . . . . .
4 try:
5 db.session.bulk_save_objects(not_normalized_records)
6 db.session.commit()
7 except sqlalchemy.exc.DBAPIError as sql_alchemy_exception:
8 # http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html
9 # http://docs.sqlalchemy.org/en/latest/core/exceptions.html
10 app.logger('DBAPIError: {}'.format(str(sql_alchemy_exception)))
11 db.session.rollback()
我想使此代码具有很高的容错性,因为我的数据库可能突然断开连接。
问题是: