Skip to content
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

- Permissive deserialization of Collection temporal extents ([#1222](https://github.com/stac-utils/pystac/pull/1222))

### Fixed

- Update usage of jsonschema ([#1215](https://github.com/stac-utils/pystac/pull/1215))
Expand All @@ -10,7 +14,6 @@

- `pystac.validation.local_validator.LocalValidator` ([#1215](https://github.com/stac-utils/pystac/pull/1215))


## [v1.8.3] - 2023-07-12

### Added
Expand Down
14 changes: 14 additions & 0 deletions pystac/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,20 @@ def from_dict(d: Dict[str, Any]) -> TemporalExtent:
"""
parsed_intervals: List[List[Optional[datetime]]] = []
for i in d["interval"]:
if isinstance(i, str):
# d["interval"] is a list of strings, so we correct the list and
# try again
# https://github.com/stac-utils/pystac/issues/1221
warnings.warn(
"A collection's temporal extent should be a list of lists, but "
"is instead a "
"list of strings. pystac is fixing this issue and continuing "
"deserialization, but note that the source "
"collection is invalid STAC.",
UserWarning,
)
d["interval"] = [d["interval"]]
return TemporalExtent.from_dict(d)
start = None
end = None

Expand Down
10 changes: 10 additions & 0 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,13 @@ def test_delete_asset_relative_no_self_link_fails(
assert asset.href in str(e.value)
assert name in collection.assets
assert os.path.exists(href)


def test_permissive_temporal_extent_deserialization(collection: Collection) -> None:
# https://github.com/stac-utils/pystac/issues/1221
collection_dict = collection.to_dict(include_self_link=False, transform_hrefs=False)
collection_dict["extent"]["temporal"]["interval"] = collection_dict["extent"][
"temporal"
]["interval"][0]
with pytest.warns(UserWarning):
Collection.from_dict(collection_dict)