docs: def atomic(self, func):
          """A decorator that wraps a function in an atomic block.
  
          Example::
  
            db = CustomSQLAlchemy()
  
            @db.atomic
            def f():
                write_to_db('a message')
                return 'OK'
  
            assert f() == 'OK'
  
          This code defines the function ``f``, which is wrapped in an
          atomic block. Wrapping a function in an atomic block gives
          several guarantees:
  
          1. The database transaction will be automatically committed if
             the function returns normally, and automatically rolled
             back if the function raises unhandled exception.
  
          2. When the transaction is committed, all objects in
             ``db.session`` will be expunged. This means that no lazy
             loading will be performed on them.
  
          3. If a transaction serialization error occurs during the
             execution of the function, the function will be
             re-executed. (It might be re-executed several times.)
  
          Atomic blocks can be nested, but in this case the outermost
          block takes full control of transaction's life-cycle, and
          inner blocks do nothing.
  
          """
  
          @wraps(func)
          def wrapper(*args, **kwargs):
              session = self.session
              session_info = session.info
              if session_info.get(_ATOMIC_FLAG_SESSION_INFO_KEY):
                  return func(*args, **kwargs)
              f = retry_on_deadlock(session)(func)
              session_info[_ATOMIC_FLAG_SESSION_INFO_KEY] = True
              try:
                  result = f(*args, **kwargs)
                  session.flush()
                  session.expunge_all()
                  session.commit()
                  return result
              except Exception:
                  session.rollback()
                  raise
              finally:
                  session_info[_ATOMIC_FLAG_SESSION_INFO_KEY] = False
  
          return wrapper