-
Notifications
You must be signed in to change notification settings - Fork 122
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
Conversation
@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. |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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.
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.
3750adb
to
36303f6
Compare
Related Issue(s): #
Description:
Fixes the logic in
serialization.identify.identify_stac_object_type
for all STAC object v0.8.* and aboveAs 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 returnsNone
if the dict is not a STAC object, andserialization.identify.identify_stac_object
raises aSTACTypeError
in this caseRemoves 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:
scripts/format
)scripts/test
)