Repository navigation
Normalize OCLC numbers in import records to prevent duplicate editions - #14500
Conversation
|
Thanks for the PR, @pranshup04! @cdrini is assigned to this PR and currently has:
PR triage checklist (maintainers / Pierre)
Note This comment was automatically generated by Pierre, Open Library's PR first-touch assistant, on behalf of @mekarpeles. This is NOT a code review or sign-off. |
openlibrary-bot
left a comment
There was a problem hiding this comment.
The PR extends normalize_record_bibids to also clean oclc_numbers on import records, using the existing normalize_oclc helper (openlibrary/utils/oclc.py) to strip ocm/ocn/on/(OCoLC) prefixes, leading zeros, and dedupe, so that an incoming record's OCLC number matches an existing edition's OCLC number regardless of which prefix style the source used. It also handles the case where oclc_numbers arrives as a bare string instead of a list. New unit tests cover the normalization logic directly and an integration test confirms a prefixed incoming OCLC number matches a catalog edition recorded with a different (or no) prefix during import preview.
Dimensions
- Correctness — 2 findings
- Security — no findings in this range. This is not a security audit.
- Accessibility — no findings. No template, JS, component, or style changes in this range — only openlibrary/catalog/add_book/init.py and its test file.
- Test coverage — no findings. test_normalize_record_bibids_oclc and test_normalize_record_bibids_string_oclc exercise the new normalization branch directly (prefixes, leading zeros, invalid/empty/None entries, string-vs-list input), and test_import_preview_matches_equivalent_oclc_numbers (parametrized over ocm/ocn/on/(OCoLC)/bare forms) exercises the full import-preview matching path end to end.
- Styleguide — no findings. No material violations — follows the existing isbn/lccn cleaning pattern in the same function, uses walrus assignment consistent with repo convention, line stays within the 162-char limit.
Findings without an in-diff anchor
- LOW · Correctness — Matched edition can accumulate duplicate OCLC numbers in different formats
Once find_match locates an existing edition via the newly-normalized oclc_numbers, update_edition_with_rec_data (openlibrary/catalog/add_book/init.py, the edition_list_fields loop around lines 958-976) merges rec's oclc_numbers into the edition's existing oclc_numbers using case-fold string comparison only (v.casefold() not in case_folded_values), not normalize_oclc equivalence. If the matched edition's stored value is e.g. "ocm30877728" and rec's normalized value is "30877728", casefold comparison treats them as different strings, so "30877728" gets appended as a second, functionally-duplicate OCLC number on the edition. A test exercising update_edition_with_rec_data (or _load with save=True) against a pre-existing edition whose oclc_numbers use a prefix would catch this; the current tests only check the preview/match outcome, not the resulting edition's oclc_numbers after an actual save.
Tip
When you've addressed the feedback and pushed your changes, comment @openlibrary-bot review on this PR to run a fresh review.
Note
Automated review by @openlibrary-bot on behalf of @mekarpeles. This is not an approval or a sign-off, and it does not satisfy a required review.
|
I disagree with the bot's comments. OCNs should be stored normalized. If we have existing un-normalised OCNs in the data, they should be corrected, and with this PR, correct OCNs will accumulate. |
…o prevent duplicate editions
69eaef3 to
f5ff019
Compare
There was a problem hiding this comment.
Agree with @hornc ; there are only 150 cases with the prefix: https://openlibrary.org/query.json?type=/type/edition&oclc~=o*&oclc&limit=500
Otherwise lgtm, thank you @pranshup04 !
|
@openlibrary-bot review |
openlibrary-bot
left a comment
There was a problem hiding this comment.
Normalizes OCLC numbers (ocm/ocn/on/(OCoLC) prefixes, leading zeros) on incoming import records so they match editions already stored with bare OCLC numbers, fixing the duplicate-edition preview bug from #14496.
🎫 Ticket compliance analysis 🔶
#14496 - Partially compliant
Compliant requirements:
- Incoming OCLC numbers (ocm/ocn/on/(OCoLC) prefixes, leading zeros, duplicates) are normalized to bare numbers before matching
- Preview matches an existing edition whose stored OCLC number is bare against an incoming prefixed equivalent
Non-compliant requirements:
- Preview still fails to match when the existing edition's own stored OCLC number is itself prefixed, since the candidate lookup is an exact string match against the stored value
Dimensions
- Correctness — 1 finding
- Security — no findings in this range. This is not a security audit.
- Accessibility — no findings. No template, JS, component or style changes in this range.
- Test coverage — no findings. New tests cover normalize_record_bibids directly and an end-to-end preview match; they fail without the fix.
- Styleguide — no findings. New code follows the existing normalize_record_bibids pattern for isbn/lccn fields.
Tip
A new review starts automatically about 10 minutes after your last push. To start it sooner, a maintainer can re-request a review, or you can comment @openlibrary-bot review on this PR.
Note
Automated review by @openlibrary-bot. This is not an approval or a sign-off, and it does not satisfy a required review.
|
@openlibrary-bot We've decided that is not an issue ; can you please approve the review? |
|
Apologies for the stall here folks, we're testing a new automated code review flow which is currently preventing me from merging! Working on resolving. |
|
We got there :D Thank you @RayBB for helping us find the new location of the "Dismiss review" button 😁 |
…rmalize-oclc-imports Normalize OCLC numbers in import records to prevent duplicate editions
…rmalize-oclc-imports Normalize OCLC numbers in import records to prevent duplicate editions
…rmalize-oclc-imports Normalize OCLC numbers in import records to prevent duplicate editions
Closes #14496
What does this PR achieve?
Normalizes incoming OCLC numbers during book import so prefixed or zero-padded values can match existing editions stored with bare control numbers. This prevents the import preview from proposing a duplicate edition when the OCLC number is the only matching identifier.
Technical
normalize_oclc()innormalize_record_bibids()before edition matching.Testing
ocm,ocn,on, and(OCoLC)prefixes, leading zeros, and bare values. The tests verify that the import preview resolves to the existing edition.pytest openlibrary/catalog/add_book/tests openlibrary/tests/contribute/test_identifiers.pyin Docker. All 229 tests passed.Stakeholders
@cdrini