Repository: CS-SI/eodag
Pull request #980 (2024-01-10 12:42:06)

fix: astraea_eod product-type specific metadata-mapping
Fixes issue when searching `S1_SAR_GRD` on `astraea_eod`, caused by a problem when parsing its product-type specific metadata-mapping:
```
KeyError: 'aswPath'
```

github-actions[bot]: ## Test Results
    4 files  ±0      4 suites  ±0   4m 7s :stopwatch: ±0s
  448 tests +1    445 :white_check_mark: +1   3 :zzz: ±0  0 :x: ±0 
1 792 runs  +4  1 714 :white_check_mark: +4  78 :zzz: ±0  0 :x: ±0 

Results for commit e919d097. ± Comparison against base commit 149b4e5b.

[test-results]:data:application/gzip;base64,H4sIAHORnmUC/03MSw6DIBSF4a0Yxh2AXL3ebqYBhITUR4MwMt17qRXq8P9Ocnbm/GQ3dm/g1rAt+VhjTEFFvy45W8AMeYrHCEOpx5aMOaj709O/MskKTvkpA69gQ1jDKSEt30+B1J5VPgUKqPT7xKHA5fPo66VZ59nHHMySoJETEjcOQA8dwajROil1D72SrdLcIGn2/gDmxnqmCAEAAA==

github-actions[bot]: <strong>Code Coverage (Windows)</strong>

| File | Coverage |   |
| - | :-: | :-: |
| **All files** | `76%` | :white_check_mark: |

_Minimum allowed coverage is `70%`_

<p align="right">Generated by :monkey: cobertura-action against e919d09790cf44b8594db7ef33b646a32ab0c79b </p>

Patch:
diff --git a/eodag/plugins/search/qssearch.py b/eodag/plugins/search/qssearch.py
index a4bd7c20..76a7fc92 100644
--- a/eodag/plugins/search/qssearch.py
+++ b/eodag/plugins/search/qssearch.py
@@ -276,15 +276,24 @@ class QueryStringSearch(Search):
                 )
                 if other_product_for_mapping:
                     other_product_type_def_params = self.get_product_type_def_params(
-                        other_product_for_mapping,  # **kwargs
+                        other_product_for_mapping,
                     )
-                    product_type_metadata_mapping.update(
-                        other_product_type_def_params.get("metadata_mapping", {})
+                    other_product_type_mtd_mapping = (
+                        mtd_cfg_as_conversion_and_querypath(
+                            other_product_type_def_params.get("metadata_mapping", {})
+                        )
                     )
-                # from current product
-                product_type_metadata_mapping.update(
-                    self.config.products[product_type]["metadata_mapping"]
-                )
+                    # updated mapping at the end
+                    for metadata, mapping in other_product_type_mtd_mapping.items():
+                        product_type_metadata_mapping.pop(metadata, None)
+                        product_type_metadata_mapping[metadata] = mapping
+
+                # from current product, updated mapping at the end
+                for metadata, mapping in self.config.products[product_type][
+                    "metadata_mapping"
+                ].items():
+                    product_type_metadata_mapping.pop(metadata, None)
+                    product_type_metadata_mapping[metadata] = mapping
 
                 self.config.products[product_type][
                     "metadata_mapping"


Test patch:
diff --git a/tests/units/test_search_plugins.py b/tests/units/test_search_plugins.py
index 6e22aa91..d8401df3 100644
--- a/tests/units/test_search_plugins.py
+++ b/tests/units/test_search_plugins.py
@@ -1233,6 +1233,42 @@ class TestSearchPluginStacSearch(BaseSearchPluginTest):
         )
         self.assertNotIn("bar", products[0].properties)
 
+    @mock.patch("eodag.plugins.search.qssearch.StacSearch._request", autospec=True)
+    def test_plugins_search_stacsearch_distinct_product_type_mtd_mapping_astraea_eod(
+        self, mock__request
+    ):
+        """The metadata mapping for a astraea_eod should correctly build assets"""
+        mock__request.return_value = mock.Mock()
+        result = {
+            "features": [
+                {
+                    "id": "foo",
+                    "geometry": None,
+                    "assets": {
+                        "productInfo": {"href": "s3://foo.bar/baz/productInfo.json"}
+                    },
+                },
+            ],
+        }
+        product_type = "S1_SAR_GRD"
+        mock__request.return_value.json.side_effect = [result]
+        search_plugin = self.get_search_plugin(product_type, "astraea_eod")
+
+        products, _ = search_plugin.query(
+            productType=product_type,
+            auth=None,
+        )
+        self.assertIn("productInfo", products[0].assets)
+        self.assertEqual(
+            products[0].assets["productInfo"]["href"],
+            "s3://foo.bar/baz/productInfo.json",
+        )
+        self.assertIn("manifest.safe", products[0].assets)
+        self.assertEqual(
+            products[0].assets["manifest.safe"]["href"],
+            "s3://foo.bar/baz/manifest.safe",
+        )
+
 
 class TestSearchPluginBuildPostSearchResult(BaseSearchPluginTest):
     @mock.patch("eodag.plugins.authentication.qsauth.requests.get", autospec=True)