internetarchive/openlibrary

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

Chiusa

#13.016 aperta il 23 giu 2026

 (4 commenti) (0 reazioni) (0 assegnatari)Python (1957 fork)batch import
Affects: DataGood First IssueModule: AuthorsModule: ImportNeeds: LeadNeeds: ResponseType: Bug

Metriche repository

Star
 (6610 stelle)
Metriche merge PR
 (Merge medio 6g 2h) (126 PR mergiate in 30 g)

Descrizione

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()

Guida contributor