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 recursion error when eo band name is missing #1406

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def solar_illumination(self, v: float | None) -> None:
self.properties.pop("solar_illumination", None)

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

def to_dict(self) -> dict[str, Any]:
"""Returns this band as a dictionary.
Expand Down
13 changes: 12 additions & 1 deletion tests/extensions/test_eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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