From 1e422214aa717c3a050d255c3dd81f4871480522 Mon Sep 17 00:00:00 2001 From: Sylvain Brunato <61419125+sbrunato@users.noreply.github.com> Date: Fri, 12 Jul 2024 09:46:37 +0200 Subject: [PATCH] fix(plugins): product types discovery disabled by default on StaticStacSearch (#1259) --- eodag/api/core.py | 22 +++++++++++++------- eodag/plugins/search/static_stac_search.py | 6 ++++++ tests/integration/test_search_stac_static.py | 9 ++++---- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/eodag/api/core.py b/eodag/api/core.py index b35b561a2..0b9345208 100644 --- a/eodag/api/core.py +++ b/eodag/api/core.py @@ -743,6 +743,11 @@ def discover_product_types( search_plugin: Union[Search, Api] = next( self._plugins_manager.get_search_plugins(provider=provider) ) + # check after plugin init if still fetchable + if not getattr(search_plugin.config, "discover_product_types", {}).get( + "fetch_url" + ): + continue # append auth to search plugin if needed if getattr(search_plugin.config, "need_auth", False): auth_plugin = self._plugins_manager.get_auth_plugin( @@ -1598,6 +1603,10 @@ def _fetch_external_product_type(self, provider: str, product_type: str): plugins = self._plugins_manager.get_search_plugins(provider=provider) plugin = next(plugins) + # check after plugin init if still fetchable + if not getattr(plugin.config, "discover_product_types", {}).get("fetch_url"): + return None + kwargs: Dict[str, Any] = {"productType": product_type} # append auth if needed @@ -1726,18 +1735,15 @@ def _prepare_search( product_type not in self._plugins_manager.product_type_to_provider_config_map.keys() ): - logger.debug( - f"Fetching external product types sources to find {product_type} product type" - ) if provider: # Try to get specific product type from external provider + logger.debug(f"Fetching {provider} to find {product_type} product type") self._fetch_external_product_type(provider, product_type) - if ( - not provider - or product_type - not in self._plugins_manager.product_type_to_provider_config_map.keys() - ): + if not provider: # no provider or still not found -> fetch all external product types + logger.debug( + f"Fetching external product types sources to find {product_type} product type" + ) self.fetch_product_types_list() preferred_provider = self.get_preferred_provider()[0] diff --git a/eodag/plugins/search/static_stac_search.py b/eodag/plugins/search/static_stac_search.py index 8fb4d1638..80d838a32 100644 --- a/eodag/plugins/search/static_stac_search.py +++ b/eodag/plugins/search/static_stac_search.py @@ -85,6 +85,12 @@ def __init__(self, provider: str, config: PluginConfig) -> None: "total_items_nb_key_path", "$.null" ) self.config.__dict__["pagination"].setdefault("max_items_per_page", -1) + # disable product types discovery by default (if endpoints equals to STAC API default) + if ( + getattr(self.config, "discover_product_types", {}).get("fetch_url") + == "{api_endpoint}/../collections" + ): + self.config.discover_product_types = {"fetch_url": None} def discover_product_types(self, **kwargs: Any) -> Optional[Dict[str, Any]]: """Fetch product types list from a static STAC Catalog provider using `discover_product_types` conf diff --git a/tests/integration/test_search_stac_static.py b/tests/integration/test_search_stac_static.py index 2a150b4f0..041b0e020 100644 --- a/tests/integration/test_search_stac_static.py +++ b/tests/integration/test_search_stac_static.py @@ -152,12 +152,11 @@ def test_search_stac_static_load_root_recursive(self): self.assertEqual(item.provider, self.stac_provider) self.assertEqual(item.product_type, self.product_type) - @mock.patch( - "eodag.api.core.EODataAccessGateway.fetch_product_types_list", autospec=True - ) - def test_search_stac_static(self, mock_fetch_product_types_list): + def test_search_stac_static(self): """Use StaticStacSearch plugin to search all items""" - search_result = self.dag.search(count=True) + # mock on fetch_product_types_list not needed with provider specified, + # as product types discovery must be disabled by default for stac static + search_result = self.dag.search(provider=self.static_stac_provider, count=True) self.assertEqual(len(search_result), self.root_cat_len) self.assertEqual(search_result.number_matched, self.root_cat_len) for item in search_result: