Skip to content

Commit

Permalink
fix(plugins): product types discovery disabled by default on StaticSt…
Browse files Browse the repository at this point in the history
…acSearch (#1259)
  • Loading branch information
sbrunato authored Jul 12, 2024
1 parent f457527 commit 1e42221
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
22 changes: 14 additions & 8 deletions eodag/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions eodag/plugins/search/static_stac_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions tests/integration/test_search_stac_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1e42221

Please sign in to comment.