bug(add_book): metadata cleanup loop uses literal attribute 'k' instead of variable k
Problem
In catalog/add_book/load_book.py, a loop intended to strip internal metadata keys from a matched author record before re-saving never executes because it accesses a literal attribute named "k" instead of the loop variable k.
Location
openlibrary/catalog/add_book/load_book.py — in the matched-author cleanup section (around line 324).
Bug
# Current (buggy):
for k in "last_modified", "id", "revision", "created":
if existing.k: # accesses literal attribute named "k" — not variable k
del existing.k # never executes
existing is a dict-like object. existing.k accesses the attribute literally named "k", which does not exist. The if condition is always falsy, so the del never runs. The intended cleanup of last_modified, id, revision, created keys from the existing author record never happens.
Fix
for k in "last_modified", "id", "revision", "created":
if k in existing:
del existing[k]
Impact
Matched author records retain last_modified, id, revision, created keys when passed to save_many(). Depending on how Infobase handles these fields in an update context, this may cause:
- Phantom metadata on re-saved author records
- Update failures if Infobase rejects these fields in an update payload
- Silent data inconsistency if the stale
revisionorlast_modifiedis accepted
Related
catalog/add_book/load_book.py- The code is in the author-resolution path called from
import_record_to_edition()
Hi @mekarpeles! I completely understand the issue with the literal attribute k instead of the loop variable in load_book.py. I would love to fix this bug as my first open-source contribution. Could you please assign this issue to me?
Hey, I opened a PR for this: #13051
Context
- Verified against current
master(ba72854): the bug is still present exactly as described —openlibrary/catalog/add_book/load_book.py#L322-L330.existing.kaccesses a literalkattribute rather than the loop variable, so thedelnever fires. - PR #13051 (opened 2026-06-26 by @solarrezaei11) already implements the exact fix proposed in this issue (
if k in existing: del existing[k]), a 2-line diff. It is currently open and unreviewed — only an automated Copilot pass has commented; pre-commit CI was still queued as of PAM's bot comment, and PAM flagged that the linked issue (this one) hasn't been triaged. - @pooja23847 asked to be assigned this issue on 2026-06-23, three days before #13051 was opened by a different contributor. No assignment was made in either direction, so there may be two contributors interested in the same fix.
Issue Assessment
Open questions
- Should #13051 simply be reviewed/merged rather than leaving this issue open for a fresh implementation, since it already matches the suggested fix verbatim?
- Should @pooja23847's assignment request be resolved (e.g. pointed to #13051 or offered a different task), since the fix they wanted to write already has an open PR?
🔔 Stakeholders
@hornc — tagging as the imports/metadata lead; this is in the author-import path (openlibrary/catalog/add_book/load_book.py, Module: Import), and there's an unreviewed PR (#13051) ready for a maintainer look.
Full triage checklist
- [ ] Triage — correct labels applied or removed
- [ ] Problem / opportunity — problem is clear, audience identified, actionable
- [ ] Scope — issue is well-scoped; does not try to do too many things
- [ ] Justification — reasoning and impact stated; sufficient for leads to prioritize
- [ ] Success & testing criteria — defines what "done" looks like, verifiable by a contributor
- [ ] Proposal & breakdown — concrete plan present; checklist actionable for a contributor
- [ ] If bug: environment & repro steps — browser, version, local vs prod; steps to reproduce
- [ ] Risks, concerns, open questions — identified and surfaced
- [ ] Richy context — relevant code, commits, PRs reviewed; no duplicate found
- [ ] References — screenshots, designs, docs, and links present where needed
[!NOTE] This comment was automatically generated by Richy, Open Library's issue enrichment assistant, on behalf of @mekarpeles. This is NOT a sign-off. This issue needs lead review before work begins.
Hi! I'd like to work on this issue. I'm new to Open Library and would love to contribute.
@TechGenius-Karan currently has a PR open for this issue that is in review.
Hi! I'm a first-time contributor to OpenLibrary and I'd like to work on this issue.
Could you please assign this issue to me if it's available?
Thank you!