code: def in_session(self):
          
          session = self.get_session()
          try:
              yield session
              session.commit()
          except IntegrityError:
              session.rollback()
              raise DuplicateError("Duplicate unique value detected!")
          except (OperationalError, DisconnectionError):
              session.rollback()
              self.close()
              logger.warn("Database Connection Lost!")
              raise DatabaseConnectionError()
          except Exception:
              session.rollback()
              raise
          finally:
              session.close()
docs: Provide a session scope around a series of operations.