code: def _txn_retry_loop(conn, callback):
      
      with conn.begin():
          while True:
              try:
                  with _NestedTransaction(conn):
                      ret = callback(conn)
                      return ret
              except sqlalchemy.exc.DatabaseError as e:
                  if isinstance(e.orig, psycopg2.OperationalError):
                      if e.orig.pgcode == psycopg2.errorcodes.SERIALIZATION_FAILURE:
                          continue
                  raise
docs: Inner transaction retry loop.
  
      ``conn`` may be either a Connection or a Session, but they both
      have compatible ``begin()`` and ``begin_nested()`` methods.