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

KeyError: 'feed' when using format other than 'json' #42

Closed
chuckwondo opened this issue Apr 22, 2024 · 2 comments · Fixed by #43
Closed

KeyError: 'feed' when using format other than 'json' #42

chuckwondo opened this issue Apr 22, 2024 · 2 comments · Fixed by #43
Labels
bug Something isn't working

Comments

@chuckwondo
Copy link
Collaborator

When performing a query with a format other than "json", a KeyError is raised.

$ python -c "import cmr; cmr.queries.GranuleQuery().format('umm_json').short_name('MOD02QKM').get(1)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../python_cmr/cmr/queries.py", line 73, in get
    if page_size > len(response.json()['feed']['entry']) or len(results) >= limit:
                       ~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'feed'
@chuckwondo
Copy link
Collaborator Author

I'll submit a PR for this, as I see there's also a problem with the logic in the get method regarding counting results for non-json formats as well. Specifically, for non-json formats, the length of the results list is equal to the number of pages fetched (i.e., the number or requests), not the number of items fetched. For example, for a non-json format, if I want to get 10 items, I actually get 10 pages of items. Given that the page size is 2000, this means I will actually get 20,000 items, not 10 items.

@frankinspace frankinspace added the bug Something isn't working label Apr 22, 2024
@chuckwondo
Copy link
Collaborator Author

I'll submit a PR for this, as I see there's also a problem with the logic in the get method regarding counting results for non-json formats as well. Specifically, for non-json formats, the length of the results list is equal to the number of pages fetched (i.e., the number or requests), not the number of items fetched. For example, for a non-json format, if I want to get 10 items, I actually get 10 pages of items. Given that the page size is 2000, this means I will actually get 20,000 items, not 10 items.

Correction: I don't get 10 pages of 2000 items, I get 10 pages of 10 items. So I get only 100 items, not 20,000, but still, I'm getting many more items than I want. Generally, instead of getting only n items, I'm getting n^2 items when n <= 2000, and 2000 * n items when n > 2000.

chuckwondo added a commit to chuckwondo/python_cmr that referenced this issue Apr 22, 2024
Also, fix bug in result counting that caused up to _limit^2_ results to
be feched rather than only _limit_ results.

Fixes nasa#42
frankinspace pushed a commit that referenced this issue Apr 23, 2024
* Fix KeyError for non-json query formats

Also, fix bug in result counting that caused up to _limit^2_ results to
be feched rather than only _limit_ results.

Fixes #42

* Add changelog entry
This was referenced Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants