Fix metadata cleanup loop to use variable k instead of literal attribute#13051
Fix metadata cleanup loop to use variable k instead of literal attribute#13051solarrezaei11 wants to merge 1 commit into
Conversation
The loop over 'last_modified', 'id', 'revision', 'created' was using existing.k (accessing a literal attribute named 'k') instead of the loop variable k. This meant the condition was always false and the cleanup never ran. Fixes internetarchive#13016
|
Thank you @solarrezaei11 for submitting this PR! Welcome to Open Library — looks like this is your first contribution here. 🎉 🤖 Copilot has been assigned for an initial review. The linked issue (#13016) hasn't been triaged yet — triage happens on Mondays and Fridays. There are currently ~185 open non-draft PRs ahead of yours. PR triage checklist (maintainers / Pierre)
Note This comment was automatically generated by PAM, Open Library's Project AI Manager. PAM provides status visibility, performs basic project management functions, and gives actionable feedback so contributors aren't left waiting. |
There was a problem hiding this comment.
Pull request overview
Fixes the author-metadata cleanup loop in author_import_record_to_author so it correctly uses the loop variable as a dict key when removing internal metadata fields from a matched existing author record (per #13016).
Changes:
- Replace incorrect attribute access (
existing.k) with dictionary key checks/deletions (k in existing,del existing[k]) for metadata fields (last_modified,id,revision,created).
|
Went through this to see if #13016 was still open for grabs, but the fix here already matches what the issue asks for. One gap: no test exercises this path, so a future refactor could reintroduce the same typo without anything catching it. def test_existing_author_metadata_fields_are_stripped(self, mock_site):
"""last_modified, revision, and created should be stripped from a
matched existing author before it's returned, so stale metadata
isn't sent back on the next save."""
author = {
"name": "William H. Brewer",
"key": "/authors/OL3A",
"type": {"key": "/type/author"},
}
mock_site.save(author)
found = author_import_record_to_author({"name": "William H. Brewer"})
for field in ("last_modified", "revision", "created"):
assert field not in found(Left Didn't have a working Python/infogami setup on hand to run this against docker, so I only traced it through by hand rather than executing it — worth double-checking against a real run before merging. Fix itself looks correct either way. |
Summary
Fixes #13016
The loop in
author_import_record_to_author(load_book.py:324) was usingexisting.kwhich attempts to access a literal attribute named"k"rather than the loop variablek. Since no such attribute exists, the condition was always false and the metadata fields (last_modified,id,revision,created) were never cleaned up.Change
This ensures the loop variable is used correctly as a dictionary key, so the metadata cleanup actually runs.