if exc_type:
# try to rollback, but if there are problems (connection in a bad
# state) just warn without clobbering the exception bubbling up.
- try:
- self.rollback()
- except Exception as exc2:
- warnings.warn(
- f"error rolling back the transaction on {self}: {exc2}",
- RuntimeWarning,
- )
+ if not self.closed:
+ try:
+ self.rollback()
+ except Exception as exc2:
+ warnings.warn(
+ f"error rolling back the transaction on {self}: {exc2}",
+ RuntimeWarning,
+ )
else:
self.commit()
if exc_type:
# try to rollback, but if there are problems (connection in a bad
# state) just warn without clobbering the exception bubbling up.
- try:
- await self.rollback()
- except Exception as exc2:
- warnings.warn(
- f"error rolling back the transaction on {self}: {exc2}",
- RuntimeWarning,
- )
+ if not self.closed:
+ try:
+ await self.rollback()
+ except Exception as exc2:
+ warnings.warn(
+ f"error rolling back the transaction on {self}: {exc2}",
+ RuntimeWarning,
+ )
else:
await self.commit()