相关疑难解决方法(0)

为什么 Sqlalchemy Session.close 不记录“回滚”?

# I've set echo=True when doing create_engine, so I can see all the sql stmt
# DBSession is ScopeSession(thread_local) and autocommit is False
session = DBSession() 
session.add(somemodel)
# 
try:
    session.flush()
    raise Exception()
    session.commit()
except SQLAlchemyError as e:
    session.rollback()
finally:
    session.close()
Run Code Online (Sandbox Code Playgroud)

根据 SQLAlchemy 文档:

The close() method issues a expunge_all(), and releases any transactional/connection
resources. When connections are returned to the connection pool, transactional state is
rolled back as well.
Run Code Online (Sandbox Code Playgroud)

我希望在执行“session.close()”时看到日志“rollback”

python session sqlalchemy

3
推荐指数
1
解决办法
3110
查看次数

标签 统计

python ×1

session ×1

sqlalchemy ×1