Skip to content

Confusing extension detection #1391

Open
@soxofaan

Description

@soxofaan

Using pystac 1.10.1:

import pystac

stac_obj = pystac.Catalog(
    id="foo",
    description="Foo",
    stac_extensions=[
        "https://stac-extensions.github.io/datacube/v2.2.0/schema.json"
    ]
)

assert stac_obj.ext.has("cube")

stac_obj.ext.cube

the assert works, but the last line fails with

AttributeError: 'CatalogExt' object has no attribute 'cube'

Is that intended behavior?

To use catalog.ext.cube in a generic way properly I guess I have to guard it with an additional hasattr:

if stac_obj.ext.has("cube") and hasattr(stac_obj.ext, "cube"):
    x = stac_obj.ext.cube ...

I'd hoped that stac_obj.ext.has("cube") would be just enough to use as guard

(Note: I'm aware that a Catalog is not supposed to have the datacube extension enabled, but I want to make my code robust against slightly "invalid" STAC data too)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions