Author dates with different month/day but same year are incorrectly considered a match
Problem
author_dates_match() in openlibrary/catalog/utils/__init__.py incorrectly returns True when comparing two authors who have fully specified birth/death dates that differ in month/day but share the same year. This causes false-positive author matches during catalog import.
Reproducing the bug
- Call
author_dates_match()with two authors that have different full date strings but the same birth/death years - Observe it returns
Truewhen it should returnFalse
- Expected behavior:
False— different dates, different people - Actual behavior:
True— only years are compared, full date bodies are ignored
Context
- Browser (Chrome, Safari, Firefox, etc):
- OS (Windows, Mac, etc):
- Logged in (Y/N):
- Environment (prod, dev, local): prod
Breakdown
No response
Thank you @soumojit-D48 for submitting this issue!
⚠️ Contributors, this issue will be ready to work on once:
- [ ] Triage — maintainers will add
Priority: *andLead: @*to replaceNeeds: TriageandNeeds: Lead
Context
The bug is confirmed and was already documented in the test suite. Reading openlibrary/tests/catalog/test_utils.py:80:
# FIXME: the following should properly be False:
assert author_dates_match(full_different, full_dates) # this shows matches are only occurring on year, full dates are ignored!
This test was added alongside PR #11150 (merged) with a known-bad assertion — it deliberately documents the broken behavior rather than asserting the correct one.
Root cause — author_dates_match() in openlibrary/catalog/utils/__init__.py:50 always falls back to year-only comparison via re_year = re.compile(r"\b(\d{4})\b"). When both dates share a year but differ in month/day (e.g., "01 January 1650" vs "01 December 1650"), the regex extracts 1650 from both and the function returns True. The docstring even states this explicitly: "Only compares years."
Call site — the function is used in openlibrary/catalog/add_book/load_book.py:249 during catalog import entity matching, so incorrect matches can cause distinct authors to be merged.
Issue Assessment
Open questions
- Should year-only dates continue to match full dates? (e.g., should
"1650"match"01 January 1650"?) The current fallback-to-year logic makes this work, and the behavior should be preserved by any fix. - Are there catalog records in production where this false-positive has already caused author merges? This would inform urgency.
Action items
- [ ] Convert the existing
# FIXMEtest atopenlibrary/tests/catalog/test_utils.py:80to assertFalseonce the fix is in place — it already defines the correct expected behavior - [ ] Update
author_dates_match()to returnFalsewhen both dates carry month/day precision and differ (while preserving year-only-vs-full-date tolerance)
Suggested breakdown
- [ ] Write a failing test for the reported scenario (pairs of full dates sharing a year but differing in month/day) — Good First Issue candidate
- [ ] Update
author_dates_match()logic to detect when both date strings contain non-year information, and compare them directly rather than falling back to year extraction - [ ] Update the FIXME assertion in
openlibrary/tests/catalog/test_utils.py:80toassert not author_dates_match(full_different, full_dates)
cc @hornc (catalog/import)
Full triage checklist (maintainers / Richy)
- [ ] Triage — correct labels applied or removed
- [x] Problem / opportunity — problem is clear, audience identified, actionable
- [x] Scope — issue is well-scoped; does not try to do too many things
- [ ] Justification — production impact (false author merges) not quantified; urgency unclear
- [ ] Success & testing criteria — no explicit success criteria stated; can be inferred from FIXME test
- [ ] Proposal & breakdown — no fix approach proposed; breakdown added above
- [ ] If bug: environment & repro steps — browser/OS/env fields left blank (not applicable to a function-level bug)
- [x] Risks, concerns, open questions — year-only-vs-full-date tolerance must be preserved
- [x] Richy context — relevant code, commits, PRs reviewed; bug confirmed in codebase; existing FIXME test found; no duplicate issue
- [x] References — relevant files and test locations identified
[!NOTE] This comment was automatically generated by Richy, via PAM, Open Library's Project AI Manager, on behalf of @mekarpeles. Richy is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting.
is this y2k all over again?