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,958 个派生)batch import
Affects: DataGood First IssueModule: AuthorsModule: ImportNeeds: LeadNeeds: ResponseType: Bug

仓库指标

星标
 (6,610 个星标)
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()

贡献者指南