Skip to content

Commit

Permalink
Allow nullable stac_extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jsignell authored and gadomski committed May 4, 2023
1 parent 0ea4786 commit 33ab4c3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Expand support for previous extension schema URIs ([#1091](https://github.com/stac-utils/pystac/pull/1091))
- Use `pyproject.toml` instead of `setup.py` ([#1100](https://github.com/stac-utils/pystac/pull/1100))
- `DefaultStacIO` now raises an error if it tries to write to a non-local url ([#1107](https://github.com/stac-utils/pystac/pull/1107))
- Allow instantiation of pystac objects even with `"stac_extensions": null` ([#1109](https://github.com/stac-utils/pystac/pull/1109))

### Deprecated

Expand Down
11 changes: 3 additions & 8 deletions pystac/serialization/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,10 @@ def migrate_to_latest(

if version != STACVersion.DEFAULT_STAC_VERSION:
object_migrations[info.object_type](result, version, info)
if "stac_extensions" not in result:
# Force stac_extensions property, as it makes
# downstream migration less complex
result["stac_extensions"] = []
result["stac_version"] = STACVersion.DEFAULT_STAC_VERSION
else:
# Ensure stac_extensions property for consistency
if "stac_extensions" not in result:
result["stac_extensions"] = []

# Ensure stac_extensions property for consistency
result["stac_extensions"] = result.get("stac_extensions", None) or []

pystac.EXTENSION_HOOKS.migrate(result, version, info)
for ext in result["stac_extensions"][:]:
Expand Down
10 changes: 10 additions & 0 deletions tests/serialization/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ def test_should_raise_exception_when_passing_invalid_extension_object(
match=r"^Item Assets extension does not apply to type 'object'$",
):
ItemAssetsExtension.ext(object()) # type: ignore


def test_migrate_works_even_if_stac_extensions_is_null(
test_case_1_catalog: pystac.Catalog,
) -> None:
collection = list(test_case_1_catalog.get_all_collections())[0]
collection_dict = collection.to_dict()
collection_dict["stac_extensions"] = None

pystac.Collection.from_dict(collection_dict, migrate=True)

0 comments on commit 33ab4c3

Please sign in to comment.