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

Allow nullable stac_extensions #1109

Merged
merged 1 commit into from
May 4, 2023
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 @@ -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)