PythiloLesson 7 of 8 · progress kept in this browser

Upgrade saved records without losing fields

Saved data outlives the code that wrote it. A version field lets a loader distinguish older shapes from current ones. A migration should preserve unknown fields where possible, avoid mutating the original and reject future versions that it does not understand. Applying the migration to an already-current record should be harmless.

record = {"version": 1, "name": "Ada"}
copy = dict(record)
copy["version"] = 2
print(record["version"])
Your task

Write upgrade(record). Missing version means 1. Version 1 renames name to display_name (default ""), removes name and sets version to 2. Version 2 returns a shallow copy unchanged. Preserve all other fields. Reject every other version with ValueError.