Skip to content

fix(harvester): dedupe subjects case-insensitively - #1127

Open
TahaKhan998 wants to merge 1 commit into
CERNDocumentServer:masterfrom
TahaKhan998:fix/harvester-dedupe-subjects
Open

TahaKhan998 wants to merge 1 commit into
CERNDocumentServer:masterfrom
TahaKhan998:fix/harvester-dedupe-subjects

Conversation

@TahaKhan998

@TahaKhan998 TahaKhan998 commented Dec 4, 2026 •

Copy link
Copy Markdown

harvested records were getting the same keyword twice because SubjectsMapper just mapped every inspire keyword as-is, and the update merge only matched on the exact subject string. so if inspire sent CMS from the author and CMS again from inspire (or CMS vs cms), we kept both.

fix is we dedupe on strip+casefold in SubjectsMapper (keep the first spelling), and use the same key on the subjects ListOfDictAppendUniqueUpdate so updates dont re-add case/spacing variants.

this is already on prod for some harvested records, e.g.:

Summary by CodeRabbit

  • Bug Fixes
    • Subject keywords with blank values are now excluded, and duplicates are detected regardless of surrounding whitespace or letter case. The first retained spelling is preserved.
    • Existing subjects are matched using the same whitespace- and case-insensitive comparison, helping prevent duplicate entries when metadata is updated.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

An error occurred during the review process. Please try again later.

Walkthrough

The INSPIRE harvester now deduplicates mapped subjects using trimmed, case-folded values. Its append-unique update strategy supports custom key functions, and the subjects update configuration uses this feature.

Changes: Subject deduplication

Layer / File(s) Summary
Custom keys for append-unique updates
site/cds_rdm/inspire_harvester/update/fields/base.py
ListOfDictAppendUniqueUpdate accepts an optional key_func and uses it to index current items and match incoming items. Without a custom function, it uses key_field.
Subject normalization and coverage
site/cds_rdm/inspire_harvester/transform/mappers/basic_metadata.py, site/cds_rdm/inspire_harvester/update/config.py, site/tests/inspire_harvester/test_transformer.py
SubjectsMapper skips falsey values and deduplicates subjects using trimmed, case-folded values while retaining the first spelling. The subjects update configuration uses a normalized key function. Tests cover subject deduplication and repeat language mapper assertions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: kpsherva, sakshamarora1

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant