Code RoomTransfer hangs waiting for lock
HardPrep Room Coding #1835

Transfer hangs waiting for lock

Code reviewDatabases & SQLConcurrencySenior–Staff~30 min

Review this Python (psycopg2) money-transfer function.

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 30 min
Mark a line and say what kind of problem it is.0 findings
1def transfer(conn, src, dst, amt):
2 with conn: # transaction
3 cur = conn.cursor()
4 cur.execute(
5 "UPDATE accounts SET balance = balance - %s WHERE id = %s",
6 (amt, src))
7 cur.execute(
8 "UPDATE accounts SET balance = balance + %s WHERE id = %s",
9 (amt, dst))
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.