Skip to content
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

retrieving non-STAC entities via Links throws unintended error #340

Closed
philvarner opened this issue May 13, 2021 · 2 comments
Closed

retrieving non-STAC entities via Links throws unintended error #340

philvarner opened this issue May 13, 2021 · 2 comments
Labels
bug Things which are broken
Milestone

Comments

@philvarner
Copy link
Collaborator

This code attempts to retrieve the root service-desc link as required by OAFeat. This file is OpenAPI rather than STAC.

catalog: Client = Client.open("https://earth-search.aws.element84.com/v0")
print(list(catalog.get_stac_objects('service-desc')))

Expected:

I would expect to get from this some type of error response that it's not a STAC object -- empty genexp, None, or a documented exception.

Actual:

The attempted read of the non-existant 'links' key in the object dict returns a KeyError.

  File "/Users/philvarner/.local/share/virtualenvs/stac-api-validation-suite-tzI1nfla/lib/python3.9/site-packages/pystac/stac_object.py", line 343, in get_stac_objects
    link.resolve_stac_object(root=self.get_root())
  File "/Users/philvarner/.local/share/virtualenvs/stac-api-validation-suite-tzI1nfla/lib/python3.9/site-packages/pystac/link.py", line 146, in resolve_stac_object
    obj = STAC_IO.read_stac_object(target_href, root=root)
  File "/Users/philvarner/.local/share/virtualenvs/stac-api-validation-suite-tzI1nfla/lib/python3.9/site-packages/pystac/stac_io.py", line 131, in read_stac_object
    return cls.stac_object_from_dict(d, href=uri, root=root)
  File "/Users/philvarner/.local/share/virtualenvs/stac-api-validation-suite-tzI1nfla/lib/python3.9/site-packages/pystac/serialization/__init__.py", line 37, in stac_object_from_dict
    return Catalog.from_dict(d, href=href, root=root)
  File "/Users/philvarner/.local/share/virtualenvs/stac-api-validation-suite-tzI1nfla/lib/python3.9/site-packages/pystac/catalog.py", line 786, in from_dict
    catalog_type = CatalogType.determine_type(d)
  File "/Users/philvarner/.local/share/virtualenvs/stac-api-validation-suite-tzI1nfla/lib/python3.9/site-packages/pystac/catalog.py", line 60, in determine_type
    for link in stac_json['links']:
KeyError: 'links'
@duckontheweb
Copy link
Contributor

Thanks for reporting this @philvarner. It looks like this is coming via pystac-client, which is pinned to 0.5.6, but I've verified that it's also an issue in the latest version (v1.0.0-beta.2).

I would expect to get from this some type of error response that it's not a STAC object -- empty genexp, None, or a documented exception.

Given that this method is called get_stac_objects my vote would be for raising an exception in this case.

It looks like the root cause is that in pystac.serialization.identify_stac_object any JSON objects that don't have a type field and don't match conditions for any other STAC object are assumed to be Catalogs here. We should probably implement something closer to this suggestion by checking for stac_version to see if it's a Catalog and otherwise raising an exception (since we don't claim to support STAC <v0.6 this should work fine).

It seems like having pystac.serialization.identify_stac_object raise a STACTypeException in this case would be appropriate.

We should fix this for the latest version, but also patch the other supported release lines.

@duckontheweb
Copy link
Contributor

Closed via #402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things which are broken
Projects
None yet
Development

No branches or pull requests

2 participants