Code Room
Code reviewHardcr-g200
Subject DeadlockLevel Senior–Staff~30 minCommon in Databases & SQL · Concurrency interviewsIndustries Software development

Question

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.

Talk through your review
Code to reviewpython
def transfer(conn, src, dst, amt):    with conn:  # transaction        cur = conn.cursor()        cur.execute(            "UPDATE accounts SET balance = balance - %s WHERE id = %s",            (amt, src))        cur.execute(            "UPDATE accounts SET balance = balance + %s WHERE id = %s",            (amt, dst))
Run or narrate your approach, then ask the coach.