Skip to content

Commit 9300fbe

Browse files
committed
feat: sort stac_extensions
1 parent 2dd3e85 commit 9300fbe

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

stactask/task.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,21 @@ def post_process_item(self, item: Dict[str, Any]) -> Dict[str, Any]:
262262
E.g. add software version information.
263263
264264
Most tasks should prefer to not override this method, as logic should be
265-
kept in :py:meth:`Task.process`.
265+
kept in :py:meth:`Task.process`. If you do override this method, make
266+
sure to call ``super().post_process_item()`` AFTER doing any custom
267+
post-processing, so any regular behavior can take your changes into account.
266268
267269
Args:
268270
item: An item produced by :py:meth:`Task.process`
269271
270272
Returns:
271273
Dict[str, Any]: The item with any additional attributes applied.
272274
"""
273-
return self.add_software_version_to_item(item)
275+
item = self.add_software_version_to_item(item)
276+
assert "stac_extensions" in item
277+
assert isinstance(item["stac_extensions"], list)
278+
item["stac_extensions"].sort()
279+
return item
274280

275281
@classmethod
276282
def handler(cls, payload: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]:

tests/test_task.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,16 @@ class PostProcessTask(NothingTask):
9999
version = "42"
100100

101101
def post_process_item(self, item: Dict[str, Any]) -> Dict[str, Any]:
102-
item = super().post_process_item(item)
103102
item["properties"]["foo"] = "bar"
104-
return item
103+
item["stac_extensions"].insert(0, "zzz")
104+
return super().post_process_item(item)
105105

106106
payload = PostProcessTask.handler(items)
107107
for item in payload["features"]:
108108
assert item["properties"]["foo"] == "bar"
109109
assert item["properties"]["processing:software"]["post-processing-test"] == "42"
110+
stac_extensions = item["stac_extensions"]
111+
assert item["stac_extensions"] == sorted(stac_extensions)
110112

111113

112114
def test_derived_item(derived_item_task: Task) -> None:

0 commit comments

Comments
 (0)