Skip to content

Fix recursive search in Client.get_items #799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mishaschwartz
Copy link

@mishaschwartz mishaschwartz commented May 14, 2025

Related Issue(s):

Description:

  • runs a non-recursive search when using the recursive argument is False
  • no longer fails when using /search endpoint of an API that requires that at least one collection be passed as an argument (e.g. https://planetarycomputer.microsoft.com/api/stac/v1/)
  • updates tests

PR Checklist:

  • Code is formatted
  • Tests pass
  • Changes are added to CHANGELOG.md

@jsignell jsignell self-requested a review May 15, 2025 13:07
@jsignell jsignell self-assigned this May 15, 2025
Copy link
Member

@jsignell jsignell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few suggestions, but thank you so much for opening this PR! I think it'll be a real improvement.


Return:
Iterator[Item]: Iterator of items whose parent is this
catalog.
"""
if self.conforms_to(ConformanceClasses.ITEM_SEARCH):
search = self.search(ids=ids)
if recursive:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is maybe overly cautious but I would prefer this to be:

Suggested change
if recursive:
if recursive is not False:

Just to ensure that in the (unlikely) case where someone is passing recursive=None they get recursion to match the behavior before this PR.

Comment on lines +465 to +467
except APIError:
child_catalogs = [catalog for catalog, _, _ in self.walk()]
search = self.search(ids=ids, collections=[self, *child_catalogs])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it would be pretty easy to do accidentally. I think I'd prefer to just let the error raise and make it a little harder to get every single item in planetary computer for instance.

for item in super().get_items(
*ids, recursive=recursive is None or recursive
):
for item in super().get_items(*ids, recursive=recursive):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want to account for the possibility of recursive being None here.

Suggested change
for item in super().get_items(*ids, recursive=recursive):
for item in super().get_items(
*ids, recursive=recursive is None or recursive
):

@jsignell jsignell removed their assignment May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Client.get_items has surprising recursive behaviour when using the /search endpoint
2 participants