Welcome to the Linux Foundation Forum!

Code is missing proper indentation in "Getting Started with Logging (3)"

mhite
mhite Posts: 14
edited March 14 in LFS148 Class Forum

re:

https://trainingportal.linuxfoundation.org/learn/course/getting-started-with-opentelemetry-lfs148/hands-on-lab-manual-instrumentation-logs/hands-on-lab-exercises?page=3

Code reads:

@app.route("/users", methods=["GET"])
def get_user():
    user, status = db.get_user(123)
    logging.info(f"Found user {user!s} with status {status}")
    data = {}
    if user is not None:
    data = {"id": user.id, "name": user.name, "address": user.address}
    else:
    logging.warning(f"Could not find user with id {123}")
    logging.debug(f"Collected data is {data}")
    response = make_response(data, status)
    logging.debug(f"Generated response {response}")
    return response

Notice if/else missing appropriate indentation. Should probably read:

@app.route("/users", methods=["GET"])
def get_user():
    user, status = db.get_user(123)
    logging.info(f"Found user {user!s} with status {status}")
    data = {}
    if user is not None:
        data = {"id": user.id, "name": user.name, "address": user.address}
    else:
        logging.warning(f"Could not find user with id {123}")
    logging.debug(f"Collected data is {data}")
    response = make_response(data, status)
    logging.debug(f"Generated response {response}")
    return response

Categories

Upcoming Training