Warn instead of failing on same-major newer Metadata-Version (#1404) - #1405
Closed
katariyaVivek wants to merge 1 commit into
Closed
katariyaVivek wants to merge 1 commit into
katariyaVivek wants to merge 1 commit into
Conversation
Member
|
AI prematurely opened this before the issue this claims to fix has even been agreed upon. I'm closing for now until the issue itself is resolved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Metadata.from_raw(data, validate=True)rejects anyMetadata-Versionoutside a fixed allow-list, including same-major newer minors such as2.7. Per the Core Metadata spec, automated tools consuming metadata SHOULD warn whenmetadata-versionis greater than the highest version they support, and MUST fail only when it has a greater major version. Compliant tools currently cannot be built on this API without reimplementing validation by hand.Root Cause
_Validator._process_metadata_versioninsrc/packaging/metadata.pyraisesInvalidMetadatafor every value not in_VALID_METADATA_VERSIONS, making thevalidate=Truepath fatal for future minors.Metadata.from_rawthen collects it as a hardExceptionGrouperror.Solution
_process_metadata_versionnow returns known versions unchanged; for an unknown version on the same major line with a numerically greater minor (ASCII digits only), it emitsUserWarning("Unknown metadata version 'X'; continuing as version 'Y'.") and accepts the value. Greater majors, older versions, and malformed values still raiseInvalidMetadata. Missing (None) still raises the required-field error.Metadata.from_raw(validate=True)clampsmetadata_ageto the latest known version when the accepted version is absent from the list, keeping field-introduction checks safe.Testing
Added to
tests/test_metadata.py:test_future_minor_metadata_version_warns(2.7,2.10): warnsUserWarningand validates.test_future_major_metadata_version_fails(3.0,1.3,bogus): still raisesExceptionGroup.Verified the new warn tests fail pre-fix (no warning emitted;
ExceptionGroupraised) and pass post-fix.Verification
python -m pytest tests/test_metadata.py: 347 passed.ruff check src/packaging/metadata.py tests/test_metadata.py: clean.ruff format --check src/packaging/metadata.py tests/test_metadata.py: clean.2.99warns+accepts;2.²,2.6.1,02.7,2.x,2., empty, and2(no dot) all raiseInvalidMetadata;validate=Falselazy path warns identically.Impact
Same-major future minors (e.g.
2.7against max supported2.6) now validate with a warning instead of raising; all other versions behave exactly as before.Compatibility
Backwards compatible: previously-valid versions unchanged; previously-rejected same-major newer minors move from hard error to warning, matching the spec's SHOULD-warn guidance.
Fixes #1404