Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PackageMetadata validation error with extra provided field #256

Merged
merged 5 commits into from
Dec 16, 2022

Conversation

aganders3
Copy link
Contributor

The PackageMetadata class is configured to ignore extra fields but instantiation can still fail (raises a KeyError) when actually provided an extra field due to this custom root validator. Based on the config this does not seem like the intended behavior.

class PackageMetadata(BaseModel):
    ....
    class Config:
        extra = Extra.ignore
    ...
    @root_validator(pre=True)
    def _validate_root(cls, values):
        if "metadata_version" not in values:
            fields = cls.__fields__
            mins = {fields[n].field_info.extra.get("min_ver", "1.0") for n in values}
            values["metadata_version"] = str(max(float(x) for x in mins))
        return values

This PR just changes that validator skip over any values not in the list of expected fields during this step.

@codecov
Copy link

codecov bot commented Nov 24, 2022

Codecov Report

Merging #256 (a75fb68) into main (367b31f) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #256   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        37           
  Lines         2807      2807           
=========================================
  Hits          2807      2807           
Impacted Files Coverage Δ
npe2/manifest/_package_metadata.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Collaborator

@nclack nclack left a comment

Choose a reason for hiding this comment

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

Thanks!

You can remove the pyside dependency in the ci. It'll cause a test to fail, but that should get fixed in #255.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@nclack nclack merged commit 7261210 into napari:main Dec 16, 2022
@aganders3 aganders3 deleted the fix-packagemetadata-extra-keys branch December 16, 2022 20:16
@kne42 kne42 added the bug Something isn't working label Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants