-
Notifications
You must be signed in to change notification settings - Fork 121
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
Confusing extension detection #1391
Comments
I'd argue that pystac is working as intended. As an implementation of the spec and its extensions, the code provided (IMO) should reflect the valid use-case, with methods and functions to help bring invalid STAC into a valid state. In this example, it's not clear what type Each extension implements its own checks to see if it is valid for an object type in the try:
cube = DatacubeExtension.ext(object)
except ExtensionTypeError:
cube = None This still won't get you datacube extension information for a catalog, however. For that, you'll need to manipulate the catalog's attributes directly via extra_fields: dict[str, Any] |
I agree, that's not the thing. |
It's a good point. has_extension just looks at the I don't have a good solution to the problem in a code sense, so maybe better documentation on |
I guess we could have If you are just trying to get the if hasattr(stac_obj.ext, "cube"):
x = stac_obj.ext.cube ... or x = getattr(stac_obj.ext, "cube", None) |
Using pystac 1.10.1:
the assert works, but the last line fails with
Is that intended behavior?
To use
catalog.ext.cube
in a generic way properly I guess I have to guard it with an additionalhasattr
: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)
The text was updated successfully, but these errors were encountered: