1
1
"""Serializers."""
2
2
import abc
3
+ from copy import deepcopy
3
4
from typing import Any
4
5
5
6
import attr
@@ -121,18 +122,24 @@ def db_to_stac(cls, collection: dict, base_url: str) -> stac_types.Collection:
121
122
Returns:
122
123
stac_types.Collection: The STAC collection object.
123
124
"""
124
- # Use dictionary unpacking to extract values from the collection dictionary
125
+ # Avoid modifying the input dict in-place ... doing so breaks some tests
126
+ collection = deepcopy (collection )
127
+
128
+ # Set defaults
125
129
collection_id = collection .get ("id" )
126
- stac_extensions = collection .get ("stac_extensions" , [])
127
- stac_version = collection .get ("stac_version" , "" )
128
- title = collection .get ("title" , "" )
129
- description = collection .get ("description" , "" )
130
- keywords = collection .get ("keywords" , [])
131
- license = collection .get ("license" , "" )
132
- providers = collection .get ("providers" , {})
133
- summaries = collection .get ("summaries" , {})
134
- extent = collection .get ("extent" , {})
135
- collection_assets = collection .get ("assets" , {})
130
+ collection .setdefault ("type" , "Collection" )
131
+ collection .setdefault ("stac_extensions" , [])
132
+ collection .setdefault ("stac_version" , "" )
133
+ collection .setdefault ("title" , "" )
134
+ collection .setdefault ("description" , "" )
135
+ collection .setdefault ("keywords" , [])
136
+ collection .setdefault ("license" , "" )
137
+ collection .setdefault ("providers" , [])
138
+ collection .setdefault ("summaries" , {})
139
+ collection .setdefault (
140
+ "extent" , {"spatial" : {"bbox" : []}, "temporal" : {"interval" : []}}
141
+ )
142
+ collection .setdefault ("assets" , {})
136
143
137
144
# Create the collection links using CollectionLinks
138
145
collection_links = CollectionLinks (
@@ -143,20 +150,7 @@ def db_to_stac(cls, collection: dict, base_url: str) -> stac_types.Collection:
143
150
original_links = collection .get ("links" )
144
151
if original_links :
145
152
collection_links += resolve_links (original_links , base_url )
153
+ collection ["links" ] = collection_links
146
154
147
155
# Return the stac_types.Collection object
148
- return stac_types .Collection (
149
- type = "Collection" ,
150
- id = collection_id ,
151
- stac_extensions = stac_extensions ,
152
- stac_version = stac_version ,
153
- title = title ,
154
- description = description ,
155
- keywords = keywords ,
156
- license = license ,
157
- providers = providers ,
158
- summaries = summaries ,
159
- extent = extent ,
160
- links = collection_links ,
161
- assets = collection_assets ,
162
- )
156
+ return stac_types .Collection (** collection )
0 commit comments