Problem
In catalog/add_book/load_book.py, an author deduplication loop uses a walrus operator with incorrect operator precedence. The dedup never works for any record with more than one author.
Location
openlibrary/catalog/add_book/load_book.py — in import_record_to_edition().
Bug
# Current (buggy):
seen = set()
for a in authors:
if key := a["key"] in seen: # walrus: key = (a["key"] in seen) — bool, not string
continue
seen.add(key) # adds False or True, not the author key string
The walrus operator := has lower precedence than in. Python parses this as key := (a["key"] in seen). So:
key is assigned the boolean result of a["key"] in seen
- After the first iteration:
seen = {False}
- For all subsequent iterations:
a["key"] in seen is False (a key string is not in {False}), so seen.add(False) is a no-op
The intended deduplication never triggers for records with 2+ authors.
Fix
seen = set()
for a in authors:
if a["key"] in seen:
continue
seen.add(a["key"])
Impact
The runtime impact is benign in most cases — downstream author-resolution logic handles actual deduplication at a different level. However, the broken loop means:
- Every record with multiple authors does redundant work
- If two authors in the same record have identical OL keys, both are passed downstream instead of one being deduplicated
Related
This is a pure author deduplication bug within import_record_to_edition(), separate from the author-matching logic in match.py.
Problem
In
catalog/add_book/load_book.py, an author deduplication loop uses a walrus operator with incorrect operator precedence. The dedup never works for any record with more than one author.Location
openlibrary/catalog/add_book/load_book.py— inimport_record_to_edition().Bug
The walrus operator
:=has lower precedence thanin. Python parses this askey := (a["key"] in seen). So:keyis assigned the boolean result ofa["key"] in seenseen = {False}a["key"] in seenisFalse(a key string is not in{False}), soseen.add(False)is a no-opThe intended deduplication never triggers for records with 2+ authors.
Fix
Impact
The runtime impact is benign in most cases — downstream author-resolution logic handles actual deduplication at a different level. However, the broken loop means:
Related
This is a pure author deduplication bug within
import_record_to_edition(), separate from the author-matching logic inmatch.py.