Skip to content

Fix aggregation of unrecognized raw metadata fields - #1452

Open
Ganesh1729-ui wants to merge 1 commit into
pypa:mainfrom
Ganesh1729-ui:fix/metadata-unknown-fields-invalid-version
Open

Ganesh1729-ui wants to merge 1 commit into
pypa:mainfrom
Ganesh1729-ui:fix/metadata-unknown-fields-invalid-version

Conversation

@Ganesh1729-ui

Copy link
Copy Markdown

Summary

Metadata.from_raw(..., validate=True) can escape its grouped validation errors when an unrecognized field is combined with a missing or invalid metadata_version. A misspelled field raises AttributeError; keys such as from_raw and from_email can also raise AttributeError or disappear from the collected errors.

Check whether each raw key names a validator before the conditional metadata-version age check. Collect keys without a validator as InvalidMetadata, including classmethod-name collisions. This lets the existing collector report both the metadata-version error and the unrecognized field.

Reproduction

from packaging.metadata import Metadata

Metadata.from_raw({"name": "example", "version": "1.0", "dynamc": ["Summary"]})

Before: AttributeError for dynamc escapes validation.

After: the documented ExceptionGroup contains InvalidMetadata for both metadata-version and dynamc.

The nine parametrized regressions cover a misspelled key and both classmethod-name collisions, each with a missing, invalid or valid metadata version. Eight fail on unchanged main; the valid-version misspelled-key case is an existing-behavior control.

Validation

  • Linux Python 3.10 and 3.13: complete configured test sessions, 62,502 passed on each, with 100% line and branch coverage.
  • Windows Python 3.13: 62,501 passed / one existing Linux-only skip.
  • Property tests: 427 passed.
  • Prescribed nox -s lint: all hooks, source/wheel build and Twine checks pass.
  • Fresh installed wheel: nine malformed-input cases and two valid/lazy controls pass; strict distribution checks pass.

Fork validation verifies the eight expected failures on unchanged main, then runs the complete patched Linux sessions and lint checks. Its helper workflow is on a separate fork-only branch; this PR changes only the validator and its tests.

@Wkhanex Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted validation at 3778cdf9bc26 on Python 3.12.14: I exercised missing, invalid (0.0), and valid (2.6) metadata versions with five unrecognized names: unknown_field, from_raw, from_email, _raw, and __dict__. All 15 cases produced grouped InvalidMetadata errors containing exactly the offending field plus the metadata-version error when applicable. The caller's input mapping remained unchanged. All 353 metadata tests passed.

Including _raw and __dict__ is a useful extension to the classmethod collisions in the added tests: these names also exist on the class but are not metadata validators. The descriptor lookup now rejects those without escaping the aggregation path.

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.

2 participants