Code RoomInventory update exception swallowed
HardPrep Room Coding #1947

Inventory update exception swallowed

Code reviewCode quality & reviewSenior–Staff~20 min

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.

0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1def record_sale(conn, sku, qty, amount):
2 cur = conn.cursor()
3 cur.execute("INSERT INTO ledger (sku, amount) VALUES (%s, %s)", (sku, amount))
4 try:
5 cur.execute("UPDATE inventory SET qty = qty - %s WHERE sku = %s", (qty, sku))
6 except Exception as e:
7 logging.warning("inventory update failed: %s", e)
8 conn.commit()
9 return "ok"
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.