Save week08.py in your exercise folder and run python week08.py --lesson 2. The lab simulates two writers by reading a version twice, commits one correction, and attempts the stale update. It then deletes the fact and checks both the source table and its derived index. All effects stay inside a temporary database; no personal address is used.
The database command performs the comparison in its WHERE condition. rowcount tells how many rows changed:
import sqlite3
db = sqlite3.connect(":memory:")
db.execute("CREATE TABLE memory (id TEXT PRIMARY KEY, value TEXT, version INTEGER)")
db.execute("INSERT INTO memory VALUES (?, ?, ?)", ("addr-9", "Office A", 3))
changed = db.execute(
"UPDATE memory SET value = ?, version = version + 1 WHERE id = ? AND version = ?",
("Office B", "addr-9", 3)
).rowcount
assert changed == 1
assert db.execute("SELECT version FROM memory WHERE id = ?", ("addr-9",)).fetchone()[0] == 4
db.close()
This complete isolated example starts at version 3 and confirms the new version is 4. The weekly file adds persistent storage and a stale second writer. If changed is zero, the identifier or expected version did not match; the application must not report a completed correction. In the lab the identifier is known, so zero identifies the intended stale-version conflict. A PASS line means the second write was rejected and deleted information stopped being actively retrievable.