Skip to content

Commit 70efbb6

Browse files
jsignellgadomski
authored andcommitted
Allow nullable stac_extensions
1 parent 0ea4786 commit 70efbb6

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Expand support for previous extension schema URIs ([#1091](https://github.com/stac-utils/pystac/pull/1091))
1919
- Use `pyproject.toml` instead of `setup.py` ([#1100](https://github.com/stac-utils/pystac/pull/1100))
2020
- `DefaultStacIO` now raises an error if it tries to write to a non-local url ([#1107](https://github.com/stac-utils/pystac/pull/1107))
21+
- Allow instantiation of pystac objects even with `"stac_extensions": null` ([#1109](https://github.com/stac-utils/pystac/pull/1109))
2122

2223
### Deprecated
2324

pystac/serialization/migrate.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,10 @@ def migrate_to_latest(
184184

185185
if version != STACVersion.DEFAULT_STAC_VERSION:
186186
object_migrations[info.object_type](result, version, info)
187-
if "stac_extensions" not in result:
188-
# Force stac_extensions property, as it makes
189-
# downstream migration less complex
190-
result["stac_extensions"] = []
191187
result["stac_version"] = STACVersion.DEFAULT_STAC_VERSION
192-
else:
193-
# Ensure stac_extensions property for consistency
194-
if "stac_extensions" not in result:
195-
result["stac_extensions"] = []
188+
189+
# Ensure stac_extensions property for consistency
190+
result["stac_extensions"] = result.get("stac_extensions", None) or []
196191

197192
pystac.EXTENSION_HOOKS.migrate(result, version, info)
198193
for ext in result["stac_extensions"][:]:

tests/serialization/test_migrate.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,13 @@ def test_should_raise_exception_when_passing_invalid_extension_object(
9999
match=r"^Item Assets extension does not apply to type 'object'$",
100100
):
101101
ItemAssetsExtension.ext(object()) # type: ignore
102+
103+
104+
def test_migrate_works_even_if_stac_extensions_is_null(
105+
test_case_1_catalog: pystac.Catalog,
106+
) -> None:
107+
collection = list(test_case_1_catalog.get_all_collections())[0]
108+
collection_dict = collection.to_dict()
109+
collection_dict["stac_extensions"] = None
110+
111+
pystac.Collection.from_dict(collection_dict, migrate=True)

0 commit comments

Comments
 (0)