Skip to content

Commit be21f29

Browse files
feat(search): Remove ECMWF search default dates #1904
~ fix default date bevaviour ~ re-set option plugin_config.dates_required behaviour ~ fix ECMWFSearch.available_values_from_contraints: must not fill default values outside from contraints set ~ fix build_search_result: sort json list parameters value to make tests easier ~ fix build_search_result _fetch_data unconsistent type - remove plugin_config "dates_required" - core.py:1825 fix v2 code not pudated + add discover_queryables_defaults, defined minimal parameters required to discover_queryables + steadify date parsing + implement indirect date computed from parmezeters + update tests ~ update integration tests: skip on misconfigured provider + core: force internal define date on search_by_id to not makes paramaters required
1 parent d88f651 commit be21f29

17 files changed

Lines changed: 1133 additions & 386 deletions

‎eodag/api/core.py‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
DEFAULT_DOWNLOAD_WAIT,
6464
DEFAULT_ITEMS_PER_PAGE,
6565
DEFAULT_MAX_ITEMS_PER_PAGE,
66+
DEFAULT_MISSION_START_DATE,
6667
DEFAULT_PAGE,
6768
GENERIC_COLLECTION,
6869
GENERIC_STAC_PROVIDER,
@@ -1162,6 +1163,7 @@ def search(
11621163
provider=provider,
11631164
**kwargs,
11641165
)
1166+
11651167
if search_kwargs.get("id"):
11661168
# Don't validate requests by ID. "id" is not queryable.
11671169
return self._search_by_id(
@@ -1452,6 +1454,15 @@ def _search_by_id(
14521454
:returns: A search result with one EO product or None at all
14531455
"""
14541456
collection = kwargs.get("collection")
1457+
# Search by id no need date restrict, set largest time definition
1458+
if "start_datetime" not in kwargs:
1459+
kwargs["start_datetime"] = DEFAULT_MISSION_START_DATE
1460+
if "end_datetime" not in kwargs:
1461+
now_utc = datetime.datetime.now(datetime.timezone.utc).replace(
1462+
microsecond=0
1463+
)
1464+
kwargs["end_datetime"] = now_utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
1465+
14551466
if collection is not None:
14561467
try:
14571468
collection = self.get_collection_from_alias(collection)
@@ -1461,6 +1472,7 @@ def _search_by_id(
14611472
search_plugins = self._plugins_manager.get_search_plugins(
14621473
**get_search_plugins_kwargs
14631474
)
1475+
14641476
# datacube query string
14651477
_dc_qs = kwargs.pop("_dc_qs", None)
14661478

@@ -1812,10 +1824,10 @@ def _do_search(
18121824

18131825
search_result = search_plugin.query(prep, **search_params)
18141826

1815-
if not isinstance(search_result.data, list):
1827+
if not isinstance(search_result, SearchResult):
18161828
raise PluginImplementationError(
18171829
"The query function of a Search plugin must return a list of "
1818-
"results, got {} instead".format(type(search_result.data))
1830+
"results, got {} instead".format(type(search_result))
18191831
)
18201832
# Filter and attach to each eoproduct in the result the plugin capable of
18211833
# downloading it (this is done to enable the eo_product to download itself
@@ -1826,7 +1838,7 @@ def _do_search(
18261838
# WARNING: this means an eo_product that has an invalid geometry can still
18271839
# be returned as a search result if there was no search extent (because we
18281840
# will not try to do an intersection)
1829-
for eo_product in search_result.data:
1841+
for eo_product in search_result:
18301842
# if collection is not defined, try to guess using properties
18311843
if eo_product.collection is None:
18321844
pattern = re.compile(r"[^\w,]+")

‎eodag/api/product/metadata_mapping.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,15 @@ def get_value(
241241
"""
242242
if isinstance(key, str):
243243
original_key = key.replace("__", ":")
244+
if original_key in kwargs:
245+
return kwargs.get(original_key)
246+
244247
key_with_COLON = key.replace("__", "_COLON_")
245248
result = kwargs.get(original_key)
246249
if result is not None:
247250
return result
248251
return kwargs.get(key_with_COLON)
252+
249253
return super().get_value(key, args, kwargs)
250254

251255
def get_field(self, field_name: str, args: Any, kwargs: Any) -> Any:

‎eodag/config.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,6 @@ class MetadataPreMapping(TypedDict, total=False):
397397
max_connections: int
398398
#: :class:`~eodag.plugins.search.build_search_result.ECMWFSearch`
399399
#: if date parameters are mandatory in the request
400-
dates_required: bool
401-
#: :class:`~eodag.plugins.search.build_search_result.ECMWFSearch`
402-
#: Whether end date should be excluded from search request or not
403400
end_date_excluded: bool
404401
#: :class:`~eodag.plugins.search.build_search_result.ECMWFSearch`
405402
#: List of parameters used to parse metadata but that must not be included to the query

‎eodag/plugins/apis/ecmwf.py‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import logging
2121
import os
22-
from datetime import datetime, timezone
2322
from typing import TYPE_CHECKING, Annotated
2423

2524
import geojson
@@ -35,8 +34,6 @@
3534
from eodag.utils import (
3635
DEFAULT_DOWNLOAD_TIMEOUT,
3736
DEFAULT_DOWNLOAD_WAIT,
38-
DEFAULT_MISSION_START_DATE,
39-
get_collection_dates,
4037
get_geometry_from_various,
4138
path_to_uri,
4239
sanitize,
@@ -135,18 +132,6 @@ def query(
135132
kwargs.get("ecmwf:levtype", ""),
136133
)
137134

138-
col_start, col_end = get_collection_dates(
139-
getattr(self.config, "collection_config", {})
140-
)
141-
# start date
142-
if "start_datetime" not in kwargs:
143-
kwargs["start_datetime"] = col_start or DEFAULT_MISSION_START_DATE
144-
# end date
145-
if "end_datetime" not in kwargs:
146-
kwargs["end_datetime"] = col_end or datetime.now(timezone.utc).isoformat(
147-
timespec="seconds"
148-
)
149-
150135
# geometry
151136
if "geometry" in kwargs:
152137
kwargs["geometry"] = get_geometry_from_various(geometry=kwargs["geometry"])
@@ -285,5 +270,6 @@ def discover_queryables(
285270
arguments)
286271
:returns: fetched queryable parameters dict
287272
"""
273+
kwargs = self.discover_queryables_defaults(kwargs)
288274
collection = kwargs.get("collection")
289275
return self.queryables_from_metadata_mapping(collection)

‎eodag/plugins/search/base.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# limitations under the License.
1818
from __future__ import annotations
1919

20+
import datetime
2021
import logging
2122
from typing import TYPE_CHECKING, Annotated, get_args
2223

@@ -37,6 +38,7 @@
3738
from eodag.types.search_args import SortByList
3839
from eodag.types.stac_metadata import CommonStacMetadata, create_stac_metadata_model
3940
from eodag.utils import (
41+
DEFAULT_MISSION_START_DATE,
4042
GENERIC_COLLECTION,
4143
copy_deepcopy,
4244
deepcopy,
@@ -111,6 +113,38 @@ def discover_collections(self, **kwargs: Any) -> Optional[dict[str, Any]]:
111113
"""Fetch collections list from provider using `discover_collections` conf"""
112114
return None
113115

116+
def discover_queryables_defaults(self, kwargs: dict[str, Any]) -> dict[str, Any]:
117+
"""Set queryables default parameters."""
118+
if "start_datetime" not in kwargs or "end_datetime" not in kwargs:
119+
# Alias
120+
if "start_datetime" not in kwargs and "start" in kwargs:
121+
kwargs["start_datetime"] = kwargs["start"]
122+
if "end_datetime" not in kwargs and "end" in kwargs:
123+
kwargs["end_datetime"] = kwargs["end"]
124+
125+
if "start_datetime" not in kwargs or "end_datetime" not in kwargs:
126+
# Collection limit
127+
(collection_start_datetime, collection_end_datetime) = get_collection_dates(
128+
getattr(self.config, "collection_config", {})
129+
)
130+
if "start_datetime" not in kwargs and collection_start_datetime is not None:
131+
kwargs["start_datetime"] = collection_start_datetime
132+
if "end_datetime" not in kwargs and collection_end_datetime is not None:
133+
kwargs["end_datetime"] = collection_end_datetime
134+
135+
if "start_datetime" not in kwargs or "end_datetime" not in kwargs:
136+
# Hardcode
137+
if "start_datetime" not in kwargs:
138+
kwargs["start_datetime"] = "{}Z".format(
139+
DEFAULT_MISSION_START_DATE[0:19]
140+
)
141+
if "end_datetime" not in kwargs:
142+
kwargs["end_datetime"] = datetime.datetime.now(
143+
datetime.timezone.utc
144+
).strftime("%Y-%m-%dT%H:%I:%SZ")
145+
146+
return kwargs
147+
114148
def discover_queryables(
115149
self, **kwargs: Any
116150
) -> Optional[dict[str, Annotated[Any, FieldInfo]]]:

0 commit comments

Comments
 (0)