From f48f6304bbb7f9b7643aeca4aa99e9336b8787d5 Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Tue, 21 Nov 2023 14:41:25 -0500 Subject: [PATCH 1/5] typo --- earthaccess/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthaccess/search.py b/earthaccess/search.py index 3fd70684..35e92f85 100644 --- a/earthaccess/search.py +++ b/earthaccess/search.py @@ -58,7 +58,7 @@ def hits(self) -> int: Returns: - number of results reproted by CMR + number of results reported by CMR """ return super().hits() From c059ad5f1eb1be4f09dce96610bc2afaef0d26b6 Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Tue, 21 Nov 2023 15:16:36 -0500 Subject: [PATCH 2/5] In DataGranules, override hits() method so that session authentication is used --- earthaccess/search.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/earthaccess/search.py b/earthaccess/search.py index 35e92f85..4ea8dd75 100644 --- a/earthaccess/search.py +++ b/earthaccess/search.py @@ -318,6 +318,25 @@ def __init__(self, auth: Any = None, *args: Any, **kwargs: Any) -> None: self._debug = False + def hits(self): + """ + Returns the number of hits the current query will return. This is done by + making a lightweight query to CMR and inspecting the returned headers. + + :returns: number of results reported by CMR + """ + + url = self._build_url() + + response = self.session.get(url, headers=self.headers, params={'page_size': 0}) + + try: + response.raise_for_status() + except exceptions.HTTPError as ex: + raise RuntimeError(ex.response.text) + + return int(response.headers["CMR-Hits"]) + def parameters(self, **kwargs: Any) -> Type[CollectionQuery]: """Provide query parameters as keyword arguments. The keyword needs to match the name of the method, and the value should either be the value or a tuple of values. From cefec13c53fba629266a388620deb6edb9a59318 Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Tue, 21 Nov 2023 15:18:53 -0500 Subject: [PATCH 3/5] add missing return type annotation --- earthaccess/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthaccess/search.py b/earthaccess/search.py index 4ea8dd75..f1a8681f 100644 --- a/earthaccess/search.py +++ b/earthaccess/search.py @@ -318,7 +318,7 @@ def __init__(self, auth: Any = None, *args: Any, **kwargs: Any) -> None: self._debug = False - def hits(self): + def hits(self) -> int: """ Returns the number of hits the current query will return. This is done by making a lightweight query to CMR and inspecting the returned headers. From 32443ca66d033e6d039188b74295fbaaad6ffd19 Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Tue, 21 Nov 2023 15:20:20 -0500 Subject: [PATCH 4/5] applies auto-formatting --- earthaccess/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthaccess/search.py b/earthaccess/search.py index f1a8681f..0ed3b61d 100644 --- a/earthaccess/search.py +++ b/earthaccess/search.py @@ -328,7 +328,7 @@ def hits(self) -> int: url = self._build_url() - response = self.session.get(url, headers=self.headers, params={'page_size': 0}) + response = self.session.get(url, headers=self.headers, params={"page_size": 0}) try: response.raise_for_status() From 290176a910f7fb231a74321a57bc75ea9defda1e Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Tue, 21 Nov 2023 15:35:06 -0500 Subject: [PATCH 5/5] update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7fd3a1e..6aefdb21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## [unreleased] +* Fix zero granules being reported for restricted datasets + ## [v0.7.1] 2023-11-08 * Bug Fixes: * Treat granules without `RelatedUrls` as not cloud-hosted.