Repository: CS-SI/eodag
Pull request #557 (2022-11-25 15:22:37)

fix: fetch only given provider if specified
When calling `dag.list_product_types(provider="some_provider")` or `dag.fetch_product_types_list(provider="some_provider")` , only request this single provider


Patch:
diff --git a/eodag/api/core.py b/eodag/api/core.py
index 037f77b7..3487b74c 100644
--- a/eodag/api/core.py
+++ b/eodag/api/core.py
@@ -541,13 +541,32 @@ class EODataAccessGateway(object):
         """
         if provider is not None and provider not in self.providers_config:
             return
-        # check if any provider has already been fetched for product types
-        # (no need go get ext_product_types conf)
-        already_fetched = False
-        for provider, provider_config in self.providers_config.items():
-            if getattr(provider_config, "product_types_fetched", False):
-                already_fetched = True
-                break
+
+        # providers discovery confs that are fetchable
+        providers_discovery_configs_fetchable = {}
+        # check if any provider has not already been fetched for product types
+        already_fetched = True
+        for provider_to_fetch, provider_config in (
+            {provider: self.providers_config[provider]}.items()
+            if provider
+            else self.providers_config.items()
+        ):
+            # get discovery conf
+            if hasattr(provider_config, "search"):
+                provider_search_config = provider_config.search
+            elif hasattr(provider_config, "api"):
+                provider_search_config = provider_config.api
+            else:
+                continue
+            discovery_conf = getattr(
+                provider_search_config, "discover_product_types", {}
+            )
+            if discovery_conf.get("fetch_url", None):
+                providers_discovery_configs_fetchable[
+                    provider_to_fetch
+                ] = discovery_conf
+                if not getattr(provider_config, "product_types_fetched", False):
+                    already_fetched = False
 
         if not already_fetched:
             # get ext_product_types conf
@@ -560,24 +579,23 @@ class EODataAccessGateway(object):
 
                 if not ext_product_types_conf:
                     # empty ext_product_types conf
-                    ext_product_types_conf = self.discover_product_types()
+                    discover_kwargs = dict(provider=provider) if provider else {}
+                    ext_product_types_conf = self.discover_product_types(
+                        **discover_kwargs
+                    )
 
             # update eodag product types list with new conf
             self.update_product_types_list(ext_product_types_conf)
 
+        # Compare current provider with default one to see if it has been modified
+        # and product types list would need to be fetched
+
         # get ext_product_types conf for user modified providers
         default_providers_config = load_default_config()
-        for provider, user_provider_config in self.providers_config.items():
-            # user discover_product_types conf
-            if hasattr(user_provider_config, "search"):
-                user_provider_search_config = user_provider_config.search
-            elif hasattr(user_provider_config, "api"):
-                user_provider_search_config = user_provider_config.api
-            else:
-                continue
-            user_discovery_conf = getattr(
-                user_provider_search_config, "discover_product_types", {}
-            )
+        for (
+            provider,
+            user_discovery_conf,
+        ) in providers_discovery_configs_fetchable.items():
             # default discover_product_types conf
             if provider in default_providers_config:
                 default_provider_config = default_providers_config[provider]


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 885c17d7..cd57addf 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -87,6 +87,7 @@ jobs:
 
     - name: Publish Unit Test Results
       uses: EnricoMi/publish-unit-test-result-action@v1
+      continue-on-error: true
       with:
         files: artifacts/**/*junit-report.xml
     - name: Publish Coverage Report
diff --git a/tests/units/test_core.py b/tests/units/test_core.py
index 7bf4ca52..5dc7d081 100644
--- a/tests/units/test_core.py
+++ b/tests/units/test_core.py
@@ -518,6 +518,13 @@ class TestCore(TestCoreBase):
         # (once per dynamically configured provider)
         self.assertEqual(mock_discover_product_types.call_count, 3)
 
+        # now check that if provider is specified, only this one is fetched
+        mock_discover_product_types.reset_mock()
+        self.dag.fetch_product_types_list(provider="foo_provider")
+        mock_discover_product_types.assert_called_once_with(
+            self.dag, provider="foo_provider"
+        )
+
     @mock.patch("eodag.api.core.get_ext_product_types_conf", autospec=True)
     @mock.patch(
         "eodag.api.core.EODataAccessGateway.discover_product_types", autospec=True