Reputation: 8051
In SQLAlchemy, after an exception, the session needs to be set again because of the rollback. Should I therefor always set the session between calls?
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()
...
Upvotes: 2
Views: 1472
Reputation: 4128
Fish:
try:
session.commit()
except SQLAlchemyError:
pprint('Not quite right...')
session.rollback()
Upvotes: 3