-
Notifications
You must be signed in to change notification settings - Fork 53
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
pystac_client/client.py
Outdated
except APIError: | ||
child_catalogs = [catalog for catalog, _, _ in self.walk()] | ||
search = self.search(ids=ids, collections=[self, *child_catalogs]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern is that without something like this, many functions that call get_items
simply don't work for planetary computer or similar APIs that enforce this required argument. This includes:
Client.get_all_items
,Client.walk
,Client.validate_all
,Client.describe
,Client.make_all_asset_hrefs_relative
,Client.make_all_asset_hrefs_absolute
Note that the spec doesn't say one way or another that these arguments must be optional so I'm guessing that planetary computer's API is still spec compliant technically. However, the examples show that a search without collections should be supported so I don't really know one way or the other how to interpret that:
Otherwise the only way to make this work for APIs like planetary computer is to override the Client class like:
import pystac_client
class Client(pystac_client.Client):
def search(self, *args, **kwargs):
if kwargs["collections"] is None:
kwargs["collections"] = [self.id *[catalog.id for catalog, _, _ in self.walk()]]
return super().search(*args, **kwargs)
pystac_client.client.Client = Client # so that sub-catalogs also use the updated search method
If that's the approach we want to go with that's fine, but maybe we should document this workaround in case users want to interact with planetary computer.
What do you think?
Co-authored-by: Julia Signell <jsignell@gmail.com>
Co-authored-by: Julia Signell <jsignell@gmail.com>
Related Issue(s):
Client.get_items
has surprising recursive behaviour when using the/search
endpoint #798Description:
False
PR Checklist: