Skip to content

Commit c4d0bd5

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 9a07b9c commit c4d0bd5

17 files changed

Lines changed: 1135 additions & 387 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,
@@ -1163,6 +1164,7 @@ def search(
11631164
provider=provider,
11641165
**kwargs,
11651166
)
1167+
11661168
if search_kwargs.get("id"):
11671169
# Don't validate requests by ID. "id" is not queryable.
11681170
return self._search_by_id(
@@ -1453,6 +1455,15 @@ def _search_by_id(
14531455
:returns: A search result with one EO product or None at all
14541456
"""
14551457
collection = kwargs.get("collection")
1458+
# Search by id no need date restrict, set largest time definition
1459+
if "start_datetime" not in kwargs:
1460+
kwargs["start_datetime"] = DEFAULT_MISSION_START_DATE
1461+
if "end_datetime" not in kwargs:
1462+
now_utc = datetime.datetime.now(datetime.timezone.utc).replace(
1463+
microsecond=0
1464+
)
1465+
kwargs["end_datetime"] = now_utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
1466+
14561467
if collection is not None:
14571468
try:
14581469
collection = self.get_collection_from_alias(collection)
@@ -1462,6 +1473,7 @@ def _search_by_id(
14621473
search_plugins = self._plugins_manager.get_search_plugins(
14631474
**get_search_plugins_kwargs
14641475
)
1476+
14651477
# datacube query string
14661478
_dc_qs = kwargs.pop("_dc_qs", None)
14671479

@@ -1813,10 +1825,10 @@ def _do_search(
18131825

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

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

eodag/api/product/metadata_mapping.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,13 @@ 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_")
245-
return kwargs.get(original_key) or kwargs.get(key_with_COLON)
248+
if key_with_COLON in kwargs:
249+
return kwargs.get(original_key)
250+
246251
return super().get_value(key, args, kwargs)
247252

248253
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)