Skip to content

Commit 87e1a24

Browse files
authoredSep 26, 2024··
Fix recursion error when eo band name is missing (#1406)
* fix: recursion error when eo band name is missing * chore: update changelog
1 parent 7d070d1 commit 87e1a24

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
- Make `get_all_collections` properly recursive ([#1361](https://github.com/stac-utils/pystac/pull/1361))
2121
- Set `Item::collection` to `None` when there is no collection ([#1400](https://github.com/stac-utils/pystac/pull/1400))
22+
- Recursion error when `name` not set on `eo:bands` ([#1406](https://github.com/stac-utils/pystac/pull/1406))
2223

2324
### Removed
2425

‎pystac/extensions/eo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def solar_illumination(self, v: float | None) -> None:
225225
self.properties.pop("solar_illumination", None)
226226

227227
def __repr__(self) -> str:
228-
return f"<Band name={self.name}>"
228+
return f"<Band name={self.properties.get('name')}>"
229229

230230
def to_dict(self) -> dict[str, Any]:
231231
"""Returns this band as a dictionary.

‎tests/extensions/test_eo.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pystac
77
from pystac import ExtensionTypeError, Item
8-
from pystac.errors import ExtensionNotImplemented
8+
from pystac.errors import ExtensionNotImplemented, RequiredPropertyMissing
99
from pystac.extensions.eo import PREFIX, SNOW_COVER_PROP, Band, EOExtension
1010
from pystac.extensions.projection import ProjectionExtension
1111
from pystac.summaries import RangeSummary
@@ -504,3 +504,14 @@ def test_ext_syntax_add(item: pystac.Item) -> None:
504504
item.ext.add("eo")
505505
assert item.ext.has("eo") is True
506506
assert isinstance(item.ext.eo, EOExtension)
507+
508+
509+
def test_required_property_missing(ext_item: pystac.Item) -> None:
510+
# https://github.com/stac-utils/pystac/issues/1402
511+
d = ext_item.to_dict(include_self_link=False, transform_hrefs=False)
512+
del d["assets"]["B1"]["eo:bands"][0]["name"]
513+
item = pystac.Item.from_dict(d)
514+
bands = item.assets["B1"].ext.eo.bands
515+
assert bands is not None
516+
with pytest.raises(RequiredPropertyMissing):
517+
bands[0].name

0 commit comments

Comments
 (0)
Please sign in to comment.