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

Fix get_collections and conformance checking behavior #120

Merged
merged 3 commits into from
Nov 17, 2021

Conversation

duckontheweb
Copy link
Collaborator

@duckontheweb duckontheweb commented Nov 11, 2021

Related Issue(s):

None

Description:

The Client.get_collections docs state that it will fallback to the pystac.Catalog behavior of following "child" links if the API landing page does not include the proper conformance class for the /collections endpoint. The actual behavior when running this against an API that lacks the conformance class is that a NotImplementedError is raised:

>>> from pystac_client import Client
>>> client = Client.open("http://api.radiant.earth/mlhub/v1")
>>> next(client.get_collections())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jduckworth/Code/stac/pystac-client/pystac_client/client.py", line 97, in get_collections
    if self._stac_io.assert_conforms_to(ConformanceClasses.COLLECTIONS):
  File "/Users/jduckworth/Code/stac/pystac-client/pystac_client/stac_api_io.py", line 225, in assert_conforms_to
    raise NotImplementedError(f"{conformance_class} not supported")
NotImplementedError: ConformanceClasses.COLLECTIONS not supported

The root cause was that StacApiIO.assert_conforms_to was being used in if statements that expected a boolean response when in fact it returned True if the API conformed and raised the above exception if it did not. Having this kind of mixed response seemed like a confusing pattern, so I changed that method to raise the exception when conformance fails and not have any return value. Code that expects a boolean response now exclusively uses the StacApiIO.conforms_to method.

PR Checklist:

  • Code is formatted
  • Tests pass
  • Changes are added to the CHANGELOG

@codecov-commenter
Copy link

codecov-commenter commented Nov 11, 2021

Codecov Report

Merging #120 (92c2abd) into main (9e010ad) will increase coverage by 1.24%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #120      +/-   ##
==========================================
+ Coverage   78.71%   79.96%   +1.24%     
==========================================
  Files           9        9              
  Lines         545      544       -1     
==========================================
+ Hits          429      435       +6     
+ Misses        116      109       -7     
Impacted Files Coverage Δ
pystac_client/client.py 81.81% <33.33%> (+1.81%) ⬆️
pystac_client/stac_api_io.py 82.07% <100.00%> (+5.43%) ⬆️

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 9e010ad...92c2abd. Read the comment docs.

duckontheweb added a commit that referenced this pull request Nov 11, 2021
@@ -7,6 +7,7 @@ pytest-cov~=2.11.1
pytest-recording~=0.11.0
pytest-console-scripts~=1.1.0
recommonmark~=0.7.1
requests-mock~=1.9.3
Copy link
Member

Choose a reason for hiding this comment

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

NBD but this will conflict with #118 (maybe auto-deconflictable?).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I'm not sure if git will just resolve it automatically since it's the same change in the same place, but either way it should be easy to resolve. I can rebase one of these PRs once the other has been merged if it helps.

@matthewhanson
Copy link
Member

This all makes sense to me WRT the behavior of the asset function. Thanks for the PR and big thanks for the additional tests

@matthewhanson matthewhanson merged commit e41c7e8 into stac-utils:main Nov 17, 2021
@duckontheweb duckontheweb deleted the fix/conformance-checks branch January 19, 2022 17:58
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.

4 participants