Skip to content

Commit 6456d5a

Browse files
committed
fix Client.get_items
1 parent 5fae268 commit 6456d5a

6 files changed

+17981
-26
lines changed

pystac_client/client.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,27 +443,34 @@ def get_collections(self) -> Iterator[Collection]:
443443
call_modifier(self.modifier, collection)
444444
yield collection
445445

446-
def get_items(
447-
self, *ids: str, recursive: bool | None = None
448-
) -> Iterator["Item_Type"]:
446+
def get_items(self, *ids: str, recursive: bool = True) -> Iterator["Item_Type"]:
449447
"""Return all items of this catalog.
450448
451449
Args:
452450
ids: Zero or more item ids to find.
453-
recursive: unused in pystac-client, but needed for falling back to pystac
451+
recursive : If True, search this catalog and all children for the
452+
item; otherwise, only search the items of this catalog. Defaults
453+
to True.
454454
455455
Return:
456456
Iterator[Item]: Iterator of items whose parent is this
457457
catalog.
458458
"""
459459
if self.conforms_to(ConformanceClasses.ITEM_SEARCH):
460-
search = self.search(ids=ids)
460+
if recursive:
461+
search = self.search(ids=ids)
462+
try:
463+
yield from search.items()
464+
return
465+
except APIError:
466+
child_catalogs = [catalog for catalog, _, _ in self.walk()]
467+
search = self.search(ids=ids, collections=[self, *child_catalogs])
468+
else:
469+
search = self.search(ids=ids, collections=[self.id])
461470
yield from search.items()
462471
else:
463472
self._warn_about_fallback("ITEM_SEARCH")
464-
for item in super().get_items(
465-
*ids, recursive=recursive is None or recursive
466-
):
473+
for item in super().get_items(*ids, recursive=recursive):
467474
call_modifier(self.modifier, item)
468475
yield item
469476

0 commit comments

Comments
 (0)