在 SQLAlchemy 中,发生异常后,由于回滚,需要再次设置会话。因此,我是否应该始终设置通话之间的会话?
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()
...