Skip to content

Raise exception on attempt to extend object not implementing that extension #370

@duckontheweb

Description

@duckontheweb

Calling, for instance, pystac.extensions.eo.EOExtension.ext on an Item that does not have the EO schema URI in its stac_extensions list will succeed and return an ItemEOExtension instance. You can then read and write fields like eo:cloud_cover even though the Item doesn't actually implement that extension.

It seems like the desired behavior here would be to raise an exception when using ext on an object that does not implement that extension for 2 reasons:

  1. When using PySTAC to read existing STAC Items, this could mask a problem with an invalid object
  2. This will interfere with the edge case where a user has custom fields with a prefix that overlaps with one of the extensions (maybe because the custom fields predate the extension). In this case, the fields should not be treated as if they are defined by the extension.

Originally raised as part of this PR comment in stac-utils/stactools

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions