Skip to content

Commit a1f8a7f

Browse files
Fix collection item retrieval (#765)
1 parent ade90b1 commit a1f8a7f

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ You can check your current version with the following command:
3030

3131
For more information, see [UP42 Python package description](https://pypi.org/project/up42-py/).
3232

33+
### 2.5.0a5
34+
**August 15, 2025**
35+
- Fix how collection items are retrieved in `BulkDeletion`.
36+
3337
### 2.5.0a4
3438
**August 6, 2025**
3539
- Added bulk deletion of items: `BulkDeletion`.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "up42-py"
3-
version = "2.5.0a4"
3+
version = "2.5.0a5"
44
description = "Python SDK for UP42, the geospatial marketplace and developer platform."
55
authors = ["UP42 GmbH <[email protected]>"]
66
license = "https://github.com/up42/up42-py/blob/master/LICENSE"

tests/test_stac.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class TestBulkDeletion:
172172
def test_should_raise_and_not_submit_when_missing_items(self):
173173
mock_stac_client = mock.Mock()
174174
mock_stac_client.get_items.return_value = iter([self.items[0]])
175+
mock_stac_client.get_collection.return_value = self.collection_with_all_items
175176
bulk_deletion = stac.BulkDeletion(self.items[0].id)
176177
bulk_deletion.stac_client = mock_stac_client
177178
with pytest.raises(stac.IncompleteCollectionDeletionError):
@@ -184,6 +185,7 @@ def test_should_delete_staged_items(self, requests_mock: req_mock.Mocker):
184185
)
185186
mock_stac_client = mock.Mock()
186187
mock_stac_client.get_items.return_value = iter(self.items)
188+
mock_stac_client.get_collection.return_value = self.collection_with_all_items
187189

188190
bulk_deletion = stac.BulkDeletion(self.items[0].id, self.items[1].id)
189191
bulk_deletion.stac_client = mock_stac_client

up42/stac.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,23 @@ def __init__(self, *item_ids: str):
113113

114114
def delete(self):
115115
items = self.stac_client.get_items(*self._item_ids)
116-
collections: set[pystac.Collection] = set()
116+
collection_ids = set()
117117
for item in items:
118-
collection = item.get_parent()
119-
collections.add(collection) # type: ignore
118+
collection_ids.add(item.collection_id)
120119

121-
for collection in collections:
122-
collection_item_ids = {item_in_collection.id for item_in_collection in collection.get_items()}
120+
for collection_id in collection_ids:
121+
collection_items = self.stac_client.get_collection(collection_id).get_items()
122+
collection_item_ids = {item_in_collection.id for item_in_collection in collection_items}
123123
missing_items = collection_item_ids - self._item_ids
124124
if missing_items:
125125
error_msg = (
126126
f"The deletion request failed because the submitted items are part of a group that must be deleted "
127-
f"together. The submitted items belong to the following collection: '{collection.id}'. All items "
127+
f"together. The submitted items belong to the following collection: '{collection_id}'. All items "
128128
f"from this collection must be deleted at once. To proceed, please add these missing item IDs "
129129
f"to your request: {list(missing_items)}."
130130
)
131131
raise IncompleteCollectionDeletionError(error_msg)
132132

133-
for collection in collections:
134-
url = host.endpoint(f"/v2/assets/stac/collections/{collection.id}")
133+
for collection_id in collection_ids:
134+
url = host.endpoint(f"/v2/assets/stac/collections/{collection_id}")
135135
self.session.delete(url=url)

0 commit comments

Comments
 (0)