Repository navigation
Fix aggregation of unrecognized raw metadata fields - #1452
Ganesh1729-ui wants to merge 1 commit into
Conversation
Wkhanex
left a comment
There was a problem hiding this comment.
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.
|
Thanks @Wkhanex for validating the descriptor-collision cases, including _raw and dict. That matches the intended guard: keys without a metadata validator are collected as InvalidMetadata instead of escaping or disappearing from the grouped validation errors. |
3778cdf to
18b11a6
Compare
Summary
Metadata.from_raw(..., validate=True)can escape its grouped validation errors when an unrecognized field is combined with a missing or invalidmetadata_version. A misspelled field raisesAttributeError; keys such asfrom_rawandfrom_emailcan also raiseAttributeErroror 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
Before:
AttributeErrorfordynamcescapes validation.After: the documented
ExceptionGroupcontainsInvalidMetadatafor bothmetadata-versionanddynamc.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
nox -s lint: all hooks, source/wheel build and Twine 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.