Code Room
Code reviewHardcr-g314
Subject Swallowed exceptionsLevel Senior–Staff~20 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this Python function that records a sale: it writes the ledger entry, then updates inventory.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewpython
def record_sale(conn, sku, qty, amount):    cur = conn.cursor()    cur.execute("INSERT INTO ledger (sku, amount) VALUES (%s, %s)", (sku, amount))    try:        cur.execute("UPDATE inventory SET qty = qty - %s WHERE sku = %s", (qty, sku))    except Exception as e:        logging.warning("inventory update failed: %s", e)    conn.commit()    return "ok"
Run or narrate your approach, then ask the coach.