Code Room
Code reviewHard
Question
Review this Python booking function meant to prevent double-booking a room.
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.
Learn the concepts
def book_room(conn, room_id, start, end): conn.set_isolation_level(REPEATABLE_READ) cur = conn.cursor() cur.execute( "SELECT count(*) FROM bookings " "WHERE room_id = %s AND tsrange(start, stop) && tsrange(%s, %s)", (room_id, start, end)) if cur.fetchone()[0] == 0: cur.execute( "INSERT INTO bookings (room_id, start, stop) VALUES (%s,%s,%s)", (room_id, start, end)) conn.commit()Run or narrate your approach, then ask the coach.