Code Room
Code reviewMediumcr-g215
Subject N plus oneLevel Mid–Senior~22 minCommon in Databases & SQL interviewsIndustries Software development

Question

Review this Python data-access code that loads authors for a batch of posts (raw SQL, no ORM).

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 attach_authors(conn, posts):    cur = conn.cursor()    for post in posts:        cur.execute(            "SELECT id, name, avatar FROM authors WHERE id = %s",            (post["author_id"],))        a = cur.fetchone()        post["author"] = {"name": a[1], "avatar": a[2]}    return posts
Run or narrate your approach, then ask the coach.