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

Raise exception in identify_stac_object for non-STAC objects #402

Merged
merged 8 commits into from
Jun 9, 2021

Conversation

duckontheweb
Copy link
Contributor

@duckontheweb duckontheweb commented Jun 3, 2021

Related Issue(s): #

Description:

  • Fixes the logic in serialization.identify.identify_stac_object_type for all STAC object v0.8.* and above
    As per retrieving non-STAC entities via Links throws unintended error #340 and this comment, this was previously falling back to identifying JSON-like dicts as Catalogs if they did not meet the other criteria.

  • serialization.identify.identify_stac_object_type now returns None if the dict is not a STAC object, and serialization.identify.identify_stac_object raises a STACTypeError in this case

  • Removes all examples for STAC versions lower than 0.8.

  • UPDATE 2021-06-04: Removes some logic in the EO extension migration and in serialization.migrate that was specific to pre-0.8 STAC versions, since this was causing a significant drop in test coverage.

PR Checklist:

  • Code is formatted (run scripts/format)
  • Tests pass (run scripts/test)
  • This PR maintains or improves overall codebase code coverage.
  • Changes are added to the CHANGELOG. See the docs for information about adding to the changelog.

@duckontheweb
Copy link
Contributor Author

@philvarner The example from #343 now throws the following exception:

>>> from pystac import Catalog
>>> c = Catalog.from_file("https://earth-search.aws.element84.com/v0")
>>> list(c.get_stac_objects('service-desc'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jduckworth/Code/pystac/pystac/stac_object.py", line 297, in get_stac_objects
    link.resolve_stac_object(root=self.get_root())
  File "/Users/jduckworth/Code/pystac/pystac/link.py", line 213, in resolve_stac_object
    obj = stac_io.read_stac_object(target_href, root=root)
  File "/Users/jduckworth/Code/pystac/pystac/stac_io.py", line 139, in read_stac_object
    return self.stac_object_from_dict(d, href=href, root=root)
  File "/Users/jduckworth/Code/pystac/pystac/stac_io.py", line 96, in stac_object_from_dict
    result = pystac.serialization.stac_object_from_dict(d, href, root)
  File "/Users/jduckworth/Code/pystac/pystac/serialization/__init__.py", line 41, in stac_object_from_dict
    info = identify_stac_object(d)
  File "/Users/jduckworth/Code/pystac/pystac/serialization/identify.py", line 369, in identify_stac_object
    raise pystac.STACTypeError("JSON does not represent a STAC object.")
pystac.errors.STACTypeError: JSON does not represent a STAC object.

@duckontheweb duckontheweb marked this pull request as draft June 3, 2021 02:19
@duckontheweb duckontheweb changed the title Raise exception in identify_stac_object for non-STAC objects [WIP] Raise exception in identify_stac_object for non-STAC objects Jun 3, 2021
@duckontheweb duckontheweb changed the title [WIP] Raise exception in identify_stac_object for non-STAC objects Raise exception in identify_stac_object for non-STAC objects Jun 3, 2021
@duckontheweb duckontheweb marked this pull request as ready for review June 3, 2021 17:14
@duckontheweb duckontheweb requested review from lossyrob and m-mohr June 3, 2021 17:15
@codecov-commenter
Copy link

codecov-commenter commented Jun 4, 2021

Codecov Report

Merging #402 (36303f6) into main (eb15669) will decrease coverage by 0.11%.
The diff coverage is 96.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #402      +/-   ##
==========================================
- Coverage   89.67%   89.56%   -0.12%     
==========================================
  Files          39       39              
  Lines        5213     5115      -98     
==========================================
- Hits         4675     4581      -94     
+ Misses        538      534       -4     
Impacted Files Coverage Δ
pystac/extensions/eo.py 96.60% <ø> (-0.36%) ⬇️
pystac/serialization/identify.py 89.61% <95.83%> (+1.42%) ⬆️
pystac/serialization/migrate.py 83.33% <100.00%> (-1.97%) ⬇️
pystac/validation/schema_uri_map.py 86.84% <0.00%> (-2.64%) ⬇️
pystac/serialization/common_properties.py 92.85% <0.00%> (-1.79%) ⬇️
pystac/validation/stac_validator.py 86.20% <0.00%> (-1.15%) ⬇️
pystac/collection.py 93.72% <0.00%> (-0.84%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb15669...36303f6. Read the comment docs.

@duckontheweb duckontheweb added this to the 1.0.0-rc.1 milestone Jun 9, 2021
Copy link
Member

@lossyrob lossyrob left a comment

Choose a reason for hiding this comment

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

Nice work! This will avoid a lot of head-scratching debug time for users, and also simplifies the library a lot by getting rid of the pre-0.8 logic.

Since we are not supporting anything pre-0.8, _identify_stac_extensions
will only ever run against ItemCollections. This removes checks that
were specific to other STAC objects or are otherwise
not relevant to ItemCollections.
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.

3 participants