Skip to content

Exception if Catalog doesn't have a description field during catalog.get_children() #464

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

Closed
philvarner opened this issue Jun 18, 2021 · 4 comments · Fixed by #487
Closed

Comments

@philvarner
Copy link
Collaborator

pystac version 0.5.6

This exception is thrown if a Catalog doesn't have a description field:

Error https://tamn.snapplanet.io/: <class 'KeyError'> 'description'
Traceback (most recent call last):
  File "/Users/philvarner/code/stac-api-validator/stac_api_validator/validate_all.py", line 22, in <module>
    (warnings, errors) = validate_api(root)
  File "/Users/philvarner/code/stac-api-validator/stac_api_validator/validations.py", line 124, in validate_api
    for collection in catalog.get_children():
  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 791, in from_dict
    description = d.pop('description')
KeyError: 'description'

This was thrown from this code:

    catalog: Client = Client.open("https://tamn.snapplanet.io")
    for collection in catalog.get_children():
        collection.validate()

The "bad" catalog without a description is here: https://tamn.snapplanet.io/catalogs/concepts

@duckontheweb
Copy link
Contributor

Thanks for reporting, this is fixed for PySTAC 1.0 by #451, but hasn't been implemented in other versions. We can look at applying that fix to the other release lines as well.

@philvarner
Copy link
Collaborator Author

I personally don't think it's necessary to apply it to other lines, as long as it's in 1.0

@duckontheweb
Copy link
Contributor

@philvarner Sorry, I should be more specific about this...

It looks like this is failing on this link from the landing page:

{
  "rel": "child",
  "title": "Concepts",
  "type": "application/json",
  "href": "https://tamn.snapplanet.io/catalogs/concepts"
}

That href points to a "child" that looks like this:

{
  "id": "concepts",
  "title": "Concepts catalogs",
  "links": [
    {
      "rel": "self",
      "type": "application/json",
      "href": "https://tamn.snapplanet.io/catalogs/concepts"
    },
    {
      "rel": "root",
      "type": "application/json",
      "href": "https://tamn.snapplanet.io"
    }
  ],
  "stac_version": "1.0.0"
}

which is not a valid STAC object. As of PySTAC 1.0.0-rc.1 this will raise a STACTypeError in pystac.serialization.identify_stac_object instead of the cryptic KeyError.

@duckontheweb
Copy link
Contributor

Actually, it looks like this gets incorrectly identified as a Catalog instead of raising a STACTypeError. I'll open a PR to fix this.

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 a pull request may close this issue.

2 participants