Skip to content

Commit

Permalink
Better error when collections across separate backends #153
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Sep 3, 2024
1 parent 4e5e79f commit 5cf49ac
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is roughly based on [Keep a Changelog](https://keepachangelog.com/en/

<!-- start changelog -->

## 0.37.1

- Better error message when requested collections are spread across separate backends ([#153](https://github.com/Open-EO/openeo-aggregator/issues/153))

## 0.37.0

- move example configs inside package source tree ([#117](https://github.com/Open-EO/openeo-aggregator/issues/117))
Expand Down
2 changes: 1 addition & 1 deletion src/openeo_aggregator/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from typing import Optional

__version__ = "0.37.0a1"
__version__ = "0.37.1a1"


def log_version_info(logger: Optional[logging.Logger] = None):
Expand Down
9 changes: 8 additions & 1 deletion src/openeo_aggregator/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,16 @@ def get_backend_candidates_for_collections(self, collections: Iterable[str]) ->
if intersection:
backend_candidates = list(intersection)
else:
# No single backend that provides each of requested collections
# Report collections that are only available on certain backends
union = functools.reduce(lambda a, b: set(a).union(b), backend_combos)
only_on = [
f"{cid!r} only on {list(backends)}"
for cid, backends in collection_backends_map.items()
if union.difference(backends)
]
raise BackendLookupFailureException(
message=f"Collections across multiple backends ({union}): {collections}."
message=f"Requested collections are not available on a single backend, but spread across separate ones: {', '.join(only_on)}."
)

_log.info(f"Backend candidates {backend_candidates} for collections {collections}")
Expand Down
5 changes: 4 additions & 1 deletion tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,10 @@ def test_get_best_backend_for_collections_basic(self, catalog, backend1, backend
assert catalog.get_backend_candidates_for_collections(["S3", "S4"]) == ["b1"]
assert catalog.get_backend_candidates_for_collections(["S4", "S5"]) == ["b2"]

with pytest.raises(OpenEOApiException, match="Collections across multiple backends"):
with pytest.raises(
OpenEOApiException,
match=r"Requested collections are not available on a single backend, but spread across separate ones: 'S3' only on \['b1'\], 'S5' only on \['b2'\]\.",
):
catalog.get_backend_candidates_for_collections(["S3", "S4", "S5"])

def test_get_collection_metadata_basic(self, catalog, backend1, backend2, requests_mock):
Expand Down

0 comments on commit 5cf49ac

Please sign in to comment.