Skip to content

Skip records with unparseable XML instead of failing ListRecords - #90

Merged
jrhoads merged 1 commit into
invalid-xml-fixfrom
skip-unparseable-records
Nov 24, 2026
Merged

jrhoads merged 1 commit into
invalid-xml-fixfrom
skip-unparseable-records

Conversation

@jrhoads

@jrhoads jrhoads commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Purpose

Follow-up to #86 for datacite/datacite#2570. It's stacked on #86, so please merge #86 first. GitHub will then retarget this PR to master.

#86 makes the reported DOI work by stripping XML-invalid characters from UTF-8 records. Some stored XML will still fail to parse for other reasons, such as broken markup or bad entities. pyoai only calls the metadata writers once the catalog has returned every record on the page, so one bad record turns the whole ListRecords response into a 500. A harvester working through that set can never get past that page.

Approach

  • Parse up front. For the datacite and oai_datacite formats, build_metadata_map now parses the stored XML for active records. The parsed element goes into the map, and the writers reuse it.
  • ListRecords skips a record whose XML can't be parsed and logs it with logging.error, which Sentry's default logging integration reports along with the DOI. The resumption token is kept, so harvesting continues.
  • GetRecord returns the OAI cannotDisseminateFormat error for that record instead of a 500.
  • Unaffected: oai_dc doesn't use the stored XML. Deleted records still show only their header.

Open Questions and Pre-Merge TODOs

  • completeListSize still counts skipped records. The OAI-PMH spec treats that number as an estimate.
  • If every record on a first page is skipped, pyoai answers noRecordsMatch. We think that's unlikely to happen in practice.

Learning

Lupo should still clean or reject C0 control characters when metadata is written, and existing affected DOIs should be repaired. That is tracked separately from this repo.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to change)

Tests

New integration tests in tests/integration/test_oai.py cover both XML formats:

  • ListRecords skips the bad record and keeps the resumption token.
  • GetRecord returns cannotDisseminateFormat for the bad record.
  • A deleted record with no XML gets only its header.
  • oai_dc still serves a record whose XML can't be parsed.

43 tests pass with pytest -m "not real". Codex reviewed the change and reported no material findings.

Reviewer, please remember our guidelines:

  • Be humble in the language and feedback you give, ask don't tell.
  • Consider using positive language as opposed to neutral when offering feedback. This is to avoid the negative bias that can occur with neutral language appearing negative.
  • Offer suggestions on how to improve code e.g. simplification or expanding clarity.
  • Ensure you give reasons for the changes you are proposing.

🤖 Generated with Claude Code

pyoai only calls the metadata writers once the catalog has returned every
record on the page, so one record whose stored XML can't be parsed turned
the whole ListRecords response into a 500 and harvesters could never get
past that page.

For the datacite and oai_datacite formats, parse the XML while building
each record's metadata map. ListRecords now skips (and logs) a record that
can't be parsed and keeps the resumption token. GetRecord returns a
cannotDisseminateFormat OAI error for it. oai_dc doesn't use the stored
XML and is unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jrhoads
jrhoads added this pull request to stack #91 November 24, 2026 11:22
@jrhoads
jrhoads merged commit e9eee0e into master Nov 24, 2026
1 check passed
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.

2 participants