diff --git a/npe2/manifest/_package_metadata.py b/npe2/manifest/_package_metadata.py index fdb3fb87..d2af3c13 100644 --- a/npe2/manifest/_package_metadata.py +++ b/npe2/manifest/_package_metadata.py @@ -174,7 +174,11 @@ class Config: 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} + mins = { + fields[n].field_info.extra.get("min_ver", "1.0") + for n in values + if n in fields + } values["metadata_version"] = str(max(float(x) for x in mins)) return values diff --git a/tests/test_package_meta.py b/tests/test_package_meta.py index 5b178909..fab9f823 100644 --- a/tests/test_package_meta.py +++ b/tests/test_package_meta.py @@ -17,3 +17,24 @@ def test_package_metadata_version(): def test_hashable(): hash(PackageMetadata(name="test", version="1.0")) + + +def test_package_metadata_extra_field(): + pkg = { + "name": "test", + "version": "1.0", + "maintainer": "bob", + "extra_field_that_is_definitely_not_in_the_model": False, + } + + try: + p = PackageMetadata(**pkg) + except Exception: + raise AssertionError( + "failed to parse PackageMetadata from a dict with an extra field" + ) + + assert p.name == "test" + assert p.version == "1.0" + assert p.maintainer == "bob" + assert not hasattr(p, "extra_field_that_is_definitely_not_in_the_model")