internetarchive/openlibrary

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

已關閉

#13,016 建立於 2026年6月23日

 (4 則留言) (0 個反應) (0 位負責人)Python (1,961 個分叉)batch import
Affects: DataGood First IssueModule: AuthorsModule: ImportNeeds: LeadNeeds: ResponseType: Bug

倉庫指標

星標
 (6,617 顆星)
PR 合併指標
 (平均合併 6天 2小時) (30 天內合併 126 個 PR)

描述

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

貢獻者指南