Skip to content

Commit 6ca98f0

Browse files
committed
added migration from 1.1 to 1.2
1 parent 21eb6c7 commit 6ca98f0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pystac/extensions/mlm.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,18 @@ def _migrate_1_0_to_1_1(obj: dict[str, Any]) -> None:
20922092

20932093
@staticmethod
20942094
def _migrate_1_1_to_1_2(obj: dict[str, Any]) -> None:
2095-
pass
2095+
if "assets" not in obj:
2096+
return
2097+
assets = obj["assets"]
2098+
model_in_assets = any(
2099+
["mlm:model" in assets[asset]["roles"] for asset in assets]
2100+
)
2101+
if not model_in_assets:
2102+
raise pystac.errors.STACError(
2103+
'Error migrating stac:mlm version: An asset with role "mlm:model" is '
2104+
"required in mlm>=1.2. Include at least one asset with role "
2105+
'"mlm:model" '
2106+
)
20962107

20972108
@staticmethod
20982109
def _migrate_1_2_to_1_3(obj: dict[str, Any]) -> None:

tests/extensions/test_mlm.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,20 @@ def test_migration_1_0_to_1_1(
11071107
assert bool(re.match(pattern, data["properties"]["mlm:framework"]))
11081108

11091109

1110+
def test_migration_1_1_to_1_2() -> None:
1111+
data: dict[str, Any] = {}
1112+
MLMExtensionHooks._migrate_1_1_to_1_2(data)
1113+
1114+
data["assets"] = {"asset1": {"roles": ["data"]}, "asset2": {"roles": ["labels"]}}
1115+
1116+
with pytest.raises(pystac.errors.STACError):
1117+
MLMExtensionHooks._migrate_1_1_to_1_2(data)
1118+
1119+
data["assets"]["asset3"] = {"roles": ["mlm:model"]}
1120+
1121+
MLMExtensionHooks._migrate_1_1_to_1_2(data)
1122+
1123+
11101124
@pytest.mark.parametrize(
11111125
("norm_by_channel", "norm_type", "norm_clip", "statistics", "value_scaling"),
11121126
(

0 commit comments

Comments
 (0)