Skip to content

Commit 5e5ffb3

Browse files
committed
Use from_dict with preserve_dict=False when reading from files.
1 parent cc89263 commit 5e5ffb3

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pystac/stac_io.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def stac_object_from_dict(
9999
d: Dict[str, Any],
100100
href: Optional[str] = None,
101101
root: Optional["Catalog_Type"] = None,
102+
preserve_dict: bool = True,
102103
) -> "STACObject_Type":
103104
if identify_stac_object_type(d) == pystac.STACObjectType.ITEM:
104105
collection_cache = None
@@ -114,15 +115,21 @@ def stac_object_from_dict(
114115
d = migrate_to_latest(d, info)
115116

116117
if info.object_type == pystac.STACObjectType.CATALOG:
117-
result = pystac.Catalog.from_dict(d, href=href, root=root, migrate=False)
118+
result = pystac.Catalog.from_dict(
119+
d, href=href, root=root, migrate=False, preserve_dict=preserve_dict
120+
)
118121
result._stac_io = self
119122
return result
120123

121124
if info.object_type == pystac.STACObjectType.COLLECTION:
122-
return pystac.Collection.from_dict(d, href=href, root=root, migrate=False)
125+
return pystac.Collection.from_dict(
126+
d, href=href, root=root, migrate=False, preserve_dict=preserve_dict
127+
)
123128

124129
if info.object_type == pystac.STACObjectType.ITEM:
125-
return pystac.Item.from_dict(d, href=href, root=root, migrate=False)
130+
return pystac.Item.from_dict(
131+
d, href=href, root=root, migrate=False, preserve_dict=preserve_dict
132+
)
126133

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

@@ -164,7 +171,7 @@ def read_stac_object(
164171
"""
165172
d = self.read_json(source)
166173
href = source if isinstance(source, str) else source.get_absolute_href()
167-
return self.stac_object_from_dict(d, href=href, root=root)
174+
return self.stac_object_from_dict(d, href=href, root=root, preserve_dict=False)
168175

169176
def save_json(
170177
self, dest: Union[str, "Link_Type"], json_dict: Dict[str, Any]

pystac/stac_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def from_file(
473473
href = make_absolute_href(href)
474474

475475
d = stac_io.read_json(href)
476-
o = cls.from_dict(d, href=href, migrate=True)
476+
o = cls.from_dict(d, href=href, migrate=True, preserve_dict=False)
477477

478478
# Set the self HREF, if it's not already set to something else.
479479
if o.get_self_href() is None:

0 commit comments

Comments
 (0)