diff --git a/CHANGELOG.md b/CHANGELOG.md index b26649f6..251d9533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Make `get_all_collections` properly recursive ([#1361](https://github.com/stac-utils/pystac/pull/1361)) - Set `Item::collection` to `None` when there is no collection ([#1400](https://github.com/stac-utils/pystac/pull/1400)) +- Recursion error when `name` not set on `eo:bands` ([#1406](https://github.com/stac-utils/pystac/pull/1406)) ### Removed diff --git a/pystac/extensions/eo.py b/pystac/extensions/eo.py index 024ad459..54b6cbcb 100644 --- a/pystac/extensions/eo.py +++ b/pystac/extensions/eo.py @@ -225,7 +225,7 @@ def solar_illumination(self, v: float | None) -> None: self.properties.pop("solar_illumination", None) def __repr__(self) -> str: - return f"" + return f"" def to_dict(self) -> dict[str, Any]: """Returns this band as a dictionary. diff --git a/tests/extensions/test_eo.py b/tests/extensions/test_eo.py index 51a670e5..a51ac6c1 100644 --- a/tests/extensions/test_eo.py +++ b/tests/extensions/test_eo.py @@ -5,7 +5,7 @@ import pystac from pystac import ExtensionTypeError, Item -from pystac.errors import ExtensionNotImplemented +from pystac.errors import ExtensionNotImplemented, RequiredPropertyMissing from pystac.extensions.eo import PREFIX, SNOW_COVER_PROP, Band, EOExtension from pystac.extensions.projection import ProjectionExtension from pystac.summaries import RangeSummary @@ -504,3 +504,14 @@ def test_ext_syntax_add(item: pystac.Item) -> None: item.ext.add("eo") assert item.ext.has("eo") is True assert isinstance(item.ext.eo, EOExtension) + + +def test_required_property_missing(ext_item: pystac.Item) -> None: + # https://github.com/stac-utils/pystac/issues/1402 + d = ext_item.to_dict(include_self_link=False, transform_hrefs=False) + del d["assets"]["B1"]["eo:bands"][0]["name"] + item = pystac.Item.from_dict(d) + bands = item.assets["B1"].ext.eo.bands + assert bands is not None + with pytest.raises(RequiredPropertyMissing): + bands[0].name