-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: raise errors when metadata discovery is not allowed #1534
Open
anesson-cs
wants to merge
5
commits into
develop
Choose a base branch
from
wide-range-with-no-data
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9901f4f
fix: update mapping of dates parameters for 'CLMS_CORINE' with 'wekeo…
anesson-cs 7a74323
feat: add a configuration keyword
anesson-cs bcc1a3e
fix: raise an error for all configurations
anesson-cs 4665cd1
fix: add and edit comments, error messages and docstrings
anesson-cs 774a65b
fix: convert parameters eodag names of ValidationError messages to th…
anesson-cs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
string_to_jsonpath, | ||
update_nested_dict, | ||
) | ||
from eodag.utils.exceptions import ValidationError | ||
|
||
if TYPE_CHECKING: | ||
from shapely.geometry.base import BaseGeometry | ||
|
@@ -1283,11 +1284,45 @@ def format_query_params( | |
config.metadata_mapping, | ||
**config.products.get(product_type, {}).get("metadata_mapping", {}), | ||
) | ||
# Initialize the configuration parameter which indicates if an error must be raised while there is a search | ||
# parameter which is not queryable. It is useful when the provider does not return any result if the search | ||
# parameter is not a queryable without raising an error by itself. | ||
# This parameter is set to False by default and the configuration at product type level has priority over the | ||
# one at provider level | ||
raise_mtd_discovery_error = ( | ||
getattr(config, "discover_metadata", {}) | ||
.get("search_param", {}) | ||
.get("raise_mtd_discovery_error", False) | ||
if isinstance( | ||
getattr(config, "discover_metadata", {}).get("search_param", {}), dict | ||
) | ||
else False | ||
) | ||
raise_mtd_discovery_error = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logic is not correct when raise_mtd_discovery_error is is True for provider and False for product type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
config.products.get(product_type, {}) | ||
.get("discover_metadata", {}) | ||
.get("search_param", {}) | ||
.get("raise_mtd_discovery_error") | ||
if isinstance( | ||
config.products.get(product_type, {}) | ||
.get("discover_metadata", {}) | ||
.get("search_param", {}), | ||
dict, | ||
) | ||
and config.products.get(product_type, {}) | ||
.get("discover_metadata", {}) | ||
.get("search_param", {}) | ||
.get("raise_mtd_discovery_error") | ||
is not None | ||
else raise_mtd_discovery_error | ||
) | ||
|
||
query_params: dict[str, Any] = {} | ||
# Get all the search parameters that are recognised as queryables by the | ||
# provider (they appear in the queryables dictionary) | ||
queryables = _get_queryables(query_dict, config, product_type_metadata_mapping) | ||
queryables = _get_queryables( | ||
query_dict, config, product_type_metadata_mapping, raise_mtd_discovery_error | ||
) | ||
|
||
for eodag_search_key, provider_search_key in queryables.items(): | ||
user_input = query_dict[eodag_search_key] | ||
|
@@ -1419,13 +1454,20 @@ def _get_queryables( | |
search_params: dict[str, Any], | ||
config: PluginConfig, | ||
metadata_mapping: dict[str, Any], | ||
raise_mtd_discovery_error: bool, | ||
) -> dict[str, Any]: | ||
"""Retrieve the metadata mappings that are query-able""" | ||
logger.debug("Retrieving queryable metadata from metadata_mapping") | ||
queryables: dict[str, Any] = {} | ||
for eodag_search_key, user_input in search_params.items(): | ||
if user_input is not None: | ||
md_mapping = metadata_mapping.get(eodag_search_key, (None, NOT_MAPPED)) | ||
# raise an error when a query param not allowed by the provider is found | ||
if not isinstance(md_mapping, list) and raise_mtd_discovery_error: | ||
raise ValidationError( | ||
f"Search parameters which are not queryable are disallowed: {eodag_search_key}", | ||
{eodag_search_key}, | ||
) | ||
_, md_value = md_mapping | ||
# query param from defined metadata_mapping | ||
if md_mapping is not None and isinstance(md_mapping, list): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some comments for this part of the code!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!