internetarchive/openlibrary

bug(add_book): metadata cleanup loop uses literal attribute 'k' instead of variable k

Open

#13,016 opened on Jun 23, 2026

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Python (1,172 forks)batch import
Affects: DataGood First IssueModule: AuthorsModule: ImportNeeds: ResponseType: Bug

Repository metrics

Stars
 (4,626 stars)
PR merge metrics
 (Avg merge 11d 13h) (95 merged PRs in 30d)

Description

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 revision or last_modified is accepted

Related

  • catalog/add_book/load_book.py
  • The code is in the author-resolution path called from import_record_to_edition()

Contributor guide