Skip to content

Commit 95aa480

Browse files
authored
fix: migrate by default (#1509)
* fix: migrate by default * chore: update changelog
1 parent 14a4626 commit 95aa480

15 files changed

+37
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Changed
6+
7+
- `migrate=True` is now the default in `from_dict` ([#1509](https://github.com/stac-utils/pystac/pull/1509))
8+
59
### Fixed
610

711
- Fall back to `epsg` when `code` is not present in the Projection extension ([#1505](https://github.com/stac-utils/pystac/pull/1505), [#1510](https://github.com/stac-utils/pystac/pull/1510))

pystac/catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ def from_dict(
12241224
d: dict[str, Any],
12251225
href: str | None = None,
12261226
root: Catalog | None = None,
1227-
migrate: bool = False,
1227+
migrate: bool = True,
12281228
preserve_dict: bool = True,
12291229
) -> C:
12301230
if migrate:

pystac/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def from_dict(
632632
d: dict[str, Any],
633633
href: str | None = None,
634634
root: Catalog | None = None,
635-
migrate: bool = False,
635+
migrate: bool = True,
636636
preserve_dict: bool = True,
637637
) -> C:
638638
from pystac.extensions.version import CollectionVersionExtension

pystac/item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def from_dict(
416416
d: dict[str, Any],
417417
href: str | None = None,
418418
root: Catalog | None = None,
419-
migrate: bool = False,
419+
migrate: bool = True,
420420
preserve_dict: bool = True,
421421
) -> T:
422422
from pystac.extensions.version import ItemVersionExtension

pystac/stac_io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,19 @@ def stac_object_from_dict(
169169

170170
if info.object_type == pystac.STACObjectType.CATALOG:
171171
result = pystac.Catalog.from_dict(
172-
d, href=href_str, root=root, migrate=False, preserve_dict=preserve_dict
172+
d, href=href_str, root=root, migrate=True, preserve_dict=preserve_dict
173173
)
174174
result._stac_io = self
175175
return result
176176

177177
if info.object_type == pystac.STACObjectType.COLLECTION:
178178
return pystac.Collection.from_dict(
179-
d, href=href_str, root=root, migrate=False, preserve_dict=preserve_dict
179+
d, href=href_str, root=root, migrate=True, preserve_dict=preserve_dict
180180
)
181181

182182
if info.object_type == pystac.STACObjectType.ITEM:
183183
return pystac.Item.from_dict(
184-
d, href=href_str, root=root, migrate=False, preserve_dict=preserve_dict
184+
d, href=href_str, root=root, migrate=True, preserve_dict=preserve_dict
185185
)
186186

187187
raise ValueError(f"Unknown STAC object type {info.object_type}")

pystac/stac_object.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ def from_dict(
647647
d: dict[str, Any],
648648
href: str | None = None,
649649
root: Catalog | None = None,
650-
migrate: bool = False,
650+
migrate: bool = True,
651651
preserve_dict: bool = True,
652652
) -> S:
653653
"""Parses this STACObject from the passed in dictionary.
@@ -659,8 +659,9 @@ def from_dict(
659659
root : Optional root catalog for this object.
660660
If provided, the root of the returned STACObject will be set
661661
to this parameter.
662-
migrate: Use True if this dict represents JSON from an older STAC object,
663-
so that migrations are run against it.
662+
migrate: By default, STAC objects and extensions are migrated to
663+
their latest supported version. Set this to False to disable
664+
this behavior.
664665
preserve_dict: If False, the dict parameter ``d`` may be modified
665666
during this method call. Otherwise the dict is not mutated.
666667
Defaults to True, which results results in a deepcopy of the

tests/extensions/test_classification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def _parse_times(a_dict: dict[str, Any]) -> None:
260260
a_dict[k] = a_dict[k].replace(microsecond=0)
261261

262262
d1 = deepcopy(item_dict)
263-
d2 = Item.from_dict(item_dict).to_dict()
263+
d2 = Item.from_dict(item_dict, migrate=False).to_dict()
264264
_parse_times(d1)
265265
_parse_times(d2)
266266
assert d1 == d2, f"Mismatch between dictionaries: \n{d1}\n{d2}"
@@ -343,7 +343,7 @@ def test_older_extension_version(landsat_item: Item) -> None:
343343
stac_extensions.add(old)
344344
item_as_dict = landsat_item.to_dict(include_self_link=False, transform_hrefs=False)
345345
item_as_dict["stac_extensions"] = list(stac_extensions)
346-
item = Item.from_dict(item_as_dict)
346+
item = Item.from_dict(item_as_dict, migrate=False)
347347
assert ClassificationExtension.has_extension(item)
348348
assert old in item.stac_extensions
349349

tests/extensions/test_eo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def test_older_extension_version(ext_item: Item) -> None:
439439
stac_extensions.add(old)
440440
item_as_dict = ext_item.to_dict(include_self_link=False, transform_hrefs=False)
441441
item_as_dict["stac_extensions"] = list(stac_extensions)
442-
item = Item.from_dict(item_as_dict)
442+
item = Item.from_dict(item_as_dict, migrate=False)
443443
assert EOExtension.has_extension(item)
444444
assert old in item.stac_extensions
445445

tests/extensions/test_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_older_extension_version(ext_item: pystac.Item) -> None:
160160
stac_extensions.add(old)
161161
item_as_dict = ext_item.to_dict(include_self_link=False, transform_hrefs=False)
162162
item_as_dict["stac_extensions"] = list(stac_extensions)
163-
item = pystac.Item.from_dict(item_as_dict)
163+
item = pystac.Item.from_dict(item_as_dict, migrate=False)
164164
assert GridExtension.has_extension(item)
165165
assert old in item.stac_extensions
166166

tests/extensions/test_projection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def test_older_extension_version(projection_landsat8_item: Item) -> None:
602602
include_self_link=False, transform_hrefs=False
603603
)
604604
item_as_dict["stac_extensions"] = list(stac_extensions)
605-
item = Item.from_dict(item_as_dict)
605+
item = Item.from_dict(item_as_dict, migrate=False)
606606
assert ProjectionExtension.has_extension(item)
607607
assert old in item.stac_extensions
608608

0 commit comments

Comments
 (0)