Exercise 1: A Real update() Method — Possible Solution ==================================================================== THE METHOD ------------------------------ def update(self, conn): non_id_fields = {name: col for name, col in self._fields.items() if name != 'id'} set_clause = ', '.join(f"{col} = ?" for col in non_id_fields.values()) values = [getattr(self, name) for name in non_id_fields] + [self.id] sql = f"UPDATE {self._table} SET {set_clause} WHERE id = ?" conn.execute(sql, values) conn.commit() VERIFIED, REAL RESULT ------------------------------ a = Author.get(conn, 1) print(a.id, a.name) # 1 Ann a.name = 'Annika' a.update(conn) refetched = Author.get(conn, 1) print(refetched.id, refetched.name) # 1 Annika other = Author.get(conn, 2) print(other.id, other.name) # 2 Bo -- untouched WHY THIS WORKS AS AN ANSWER ------------------------------ It builds a real SQL UPDATE ... SET ... WHERE id = ? statement rather than reusing save()'s own INSERT OR REPLACE (which would re-insert the entire row rather than modifying it in place, and would silently rely on every column already being set correctly rather than changing only what's genuinely different). Excluding 'id' from the SET clause specifically avoids the pointless (and in a table with foreign-key references, potentially dangerous) act of updating a row's own primary key to itself. Re-fetching row 1 afterward confirms the real change persisted through a genuine round trip to the database, and checking row 2 separately confirms the WHERE id = ? clause correctly scoped the update to exactly the one row intended.