Skip to content
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

unit tests fail intermittently upon catalog construction: "IndexError: list index out of range" #204

Open
bossie opened this issue Aug 19, 2022 · 0 comments

Comments

@bossie
Copy link
Collaborator

bossie commented Aug 19, 2022

Lately the unit tests have been failing a couple of times while constructing the layer catalog. Simply restarting the build fixes them.

Specific cases include: tests.test_views.test_health_default[0.4.0-/health?mode=basic-expected3] and tests.test_api_result.test_apply_dimension_array_concat.

Jenkins output:

Error Message
failed on setup with "IndexError: list index out of range"

Stacktrace

request = <SubRequest 'backend_implementation' for <Function test_health_default[0.4.0-/health?mode=basic-expected3]>>

    @pytest.fixture
    def backend_implementation(request) -> 'GeoPySparkBackendImplementation':
        from openeogeotrellis.backend import GeoPySparkBackendImplementation
>       backend = GeoPySparkBackendImplementation()

tests/conftest.py:119: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
openeogeotrellis/backend.py:274: in __init__
    catalog = get_layer_catalog(opensearch_enrich=True)
openeogeotrellis/layercatalog.py:755: in get_layer_catalog
    metadata = _merge_layers_with_common_name(metadata)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

metadata = {'AGERA5': {'_vito': {'data_source': {'data_glob': '/data/MEP/ECMWF/AgERA5/*/*/AgERA5_dewpoint-temperature_*.tif', 'da..., 'extent': {'spatial': {'bbox': [[-180, -56, 180, 83]]}, 'temporal': {'interval': [['2014-10-06', None]]}}, ...}, ...}

    def _merge_layers_with_common_name(metadata):
        common_names = set(m["common_name"] for m in metadata.values() if "common_name" in m)
        logger.debug(f"Creating merged collections for common names: {common_names}")
        for common_name in common_names:
            merged = {
                "id": common_name,
                "_vito": {"data_source": {
                    "type": "merged_by_common_name",
                    "common_name": common_name,
                    "merged_collections": [],
                }},
                "providers": [],
                "links": [],
                "extent": {"spatial": {"bbox": []}, "temporal": {"interval": []}},
            }
    
            for to_merge in (m for m in metadata.values() if m.get("common_name") == common_name):
                merged["_vito"]["data_source"]["merged_collections"].append(to_merge["id"])
                # Fill some fields with first hit
                for field in ["title", "description", "keywords", "version", "license", "cube:dimensions", "summaries"]:
                    if field not in merged and field in to_merge:
                        merged[field] = deepcopy(to_merge[field])
                # Fields to take union
                for field in ["providers", "links"]:
                    if isinstance(to_merge.get(field), list):
                        merged[field] += deepcopy(to_merge[field])
    
                # Take union of bands
                for band_dim in [k for k, v in to_merge["cube:dimensions"].items() if v["type"] == "bands"]:
                    if band_dim not in merged["cube:dimensions"]:
                        merged["cube:dimensions"][band_dim] = deepcopy(to_merge["cube:dimensions"][band_dim])
                    else:
                        for b in to_merge["cube:dimensions"][band_dim]["values"]:
                            if b not in merged["cube:dimensions"][band_dim]["values"]:
                                merged["cube:dimensions"][band_dim]["values"].append(b)
                for b in to_merge["summaries"]["eo:bands"]:
                    eob_names = [x["name"] for x in merged["summaries"]["eo:bands"]]
                    if b["name"] not in eob_names:
                        merged["summaries"]["eo:bands"].append(b)
                    else:
                        i = eob_names.index(b["name"])
                        merged["summaries"]["eo:bands"][i]["aliases"] = list(
                            set(merged["summaries"]["eo:bands"][i].get("aliases", []))
>                           | set(to_merge["summaries"]["eo:bands"][i].get("aliases", []))
                        )
E                       IndexError: list index out of range

openeogeotrellis/layercatalog.py:803: IndexError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant