在SQLAlchemy中,发生异常后,由于回滚,需要重新设置 session 。因此,我是否应该始终在通话之间设置 session ?
user = User('username', 'Full Name', 'password', 'email',
datetime.now(), 'username')
session.add(user)
try:
session.commit()
except SQLAlchemyError:
pprint('Not quite right...')
# the session needs to be re-instantiated in case of an exception.
# should I always do it or only if there was an exception above?
session = Session()
res = session.query(User).all()
...
最佳答案
鱼:
try:
session.commit()
except SQLAlchemyError:
pprint('Not quite right...')
session.rollback()
关于python - 异常后的 SQLAlchemy session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15472658/