Code Room
Code reviewHardcr-g210
Subject Transaction isolationLevel Senior–Staff~28 minCommon in Databases & SQL · Concurrency interviewsIndustries Software development

Question

Review this Python (psycopg2) function that posts a double-entry journal.

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 post_journal(conn, debit_acct, credit_acct, amount):    cur = conn.cursor()    cur.execute("UPDATE accounts SET balance = balance - %s WHERE id = %s",                (amount, debit_acct))    conn.commit()    cur.execute("UPDATE accounts SET balance = balance + %s WHERE id = %s",                (amount, credit_acct))    conn.commit()
Run or narrate your approach, then ask the coach.