Code Room
Code reviewMediumcr-g208
Subject Connection leakLevel Mid–Senior~22 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this Python function that runs many independent lookups in a loop.

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 enrich(pool, ids):    results = {}    for id_ in ids:        conn = pool.getconn()        cur = conn.cursor()        cur.execute("SELECT name FROM users WHERE id = %s", (id_,))        row = cur.fetchone()        if row is None:            continue        results[id_] = row[0]        cur.close()        pool.putconn(conn)    return results
Run or narrate your approach, then ask the coach.