Skip to content

fix(parsers): report an unknown XML encoding as invalid XML - #397

Merged
kevincostner17 merged 1 commit into
mainfrom
fix/parsers-unknown-xml-encoding
Sep 15, 2026
Merged

kevincostner17 merged 1 commit into
mainfrom
fix/parsers-unknown-xml-encoding

Conversation

@kevincostner17

Copy link
Copy Markdown
Contributor

Summary

ET.parse raises LookupError when the XML declaration names an encoding Python does not recognise (for example encoding="bogus"). The GPX and SDMX parsers caught only ValueError and ET.ParseError around that call, so fd.parse_domain(..., format="gpx"|"sdmx") raised instead of returning the usual result for malformed input.

This PR catches LookupError in the same clause as ET.ParseError. An unknown encoding now gives the existing invalid GPX XML: ... / invalid SDMX XML: ... (audit only) warning and empty frames, as the SDMX module docstring and docs/parsers.md describe. No other behaviour changes.

Tests

  • tests/parsers/test_gpx.py::test_unknown_xml_encoding_returns_warning_not_exception: a GPX document that declares an unknown encoding returns empty frames and an invalid GPX XML warning, with no exception.
  • tests/parsers/test_sdmx.py::test_unknown_xml_encoding_is_audit_only: the same for SDMX, with an invalid SDMX XML ... (audit only) warning.
  • Both tests fail on main and pass with this change. All existing parser tests pass unchanged.

Verification

  • ruff check .: passed
  • mypy src/freshdata: no issues
  • pytest -m "not online and not large": Python 3.12: 5136 passed, 13 skipped; Python 3.9 / pandas 1.5: 5132 passed, 17 skipped

Closes #315

ET.parse raises LookupError when the XML declaration names an encoding
Python does not know. The GPX and SDMX parsers caught only ValueError and
ET.ParseError around that call, so the LookupError escaped instead of
producing the existing "invalid GPX/SDMX XML" warning with empty frames.
Catch LookupError in the same clause as ET.ParseError.

Closes #315
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b6efdcb4-132e-49be-941d-03c8d6aea35d


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

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

FreshData benchmark report — performance

  • freshdata: ?
  • python: ?
  • platform: ?
fixture n_rows n_cols p50 s p95 s peak MB repair % false-repair % preserve % trust monotonic export %

Authored-code reduction (Metric 6)

@kevincostner17
kevincostner17 merged commit 7bdedc3 into main Sep 15, 2026
21 checks 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.

GPX/SDMX parsers raise LookupError on an unknown XML encoding instead of warning

1 participant