Skip to content

MetaData() crashes in any environment with packaging >= 26.3 - #62

Merged
pnorton-usgs merged 1 commit into
DOI-USGS:developmentfrom
jmccreight:fix_metadata_packaging_invalidversion
Aug 14, 2026
Merged

MetaData() crashes in any environment with packaging >= 26.3#62
pnorton-usgs merged 1 commit into
DOI-USGS:developmentfrom
jmccreight:fix_metadata_packaging_invalidversion

Conversation

@jmccreight

Copy link
Copy Markdown
Contributor

Problem

File "pyPRMS/metadata/metadata.py", in __filter_by_versionvar_version = Version(elem.attrib.get('version')) packaging.version.InvalidVersion: Invalid version: None

The code relied on Version(None) raising TypeError (packaging
<= 26.2 behavior) to skip elements without a version/deprecated
attribute; packaging 26.3 changed the exception to InvalidVersion,
which escapes the except TypeError handler. 63 entries in the shipped
control.xml lack the attribute, so any MetaData() call crashes.

Found via conda-forge CI for pywatershed 3.0.0, which imports pyPRMS
(conda-forge/pywatershed-feedstock#13); fresh pip environments that
resolve packaging 26.3 hit the same crash.

Fix

Check the XML attributes for None explicitly instead of relying on
exception flow. Behavior is otherwise unchanged on all packaging
versions (including that InvalidVersion still propagates for a
genuinely malformed version string, as it always did).
Declare the already-imported packaging dependency in
pyproject.toml.
Add a regression test (entries with neither attribute, and with only
deprecated, are retained).

A release including this would let downstream consumers drop temporary
packaging <26.3 pins.

MetaData.__filter_by_version relied on Version(None) raising TypeError
to skip elements without version/deprecated XML attributes. packaging
26.3 raises InvalidVersion for None, escaping the handler and crashing
MetaData() for any such element (63 in control.xml alone). Check the
attributes for None explicitly instead of exception flow; behavior is
unchanged on all packaging versions, including InvalidVersion still
propagating for genuinely malformed version strings.

Also declare the (already imported) packaging dependency in
pyproject.toml and add a regression test.
@pnorton-usgs

Copy link
Copy Markdown
Member

This looks good - I just got hit by this problem this morning! Thanks for fixing this.

@pnorton-usgs
pnorton-usgs merged commit 06b1ef3 into DOI-USGS:development Aug 14, 2026
7 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.

2 participants