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

pystac.extensions.file.MappingObject doesn't work #605

Closed
jamesvrt opened this issue Aug 13, 2021 · 1 comment · Fixed by #700
Closed

pystac.extensions.file.MappingObject doesn't work #605

jamesvrt opened this issue Aug 13, 2021 · 1 comment · Fixed by #700
Assignees
Labels
bug Things which are broken
Milestone

Comments

@jamesvrt
Copy link

jamesvrt commented Aug 13, 2021

pystac.extensions.file.MappingObject is broken and/or the docs should not specify to use it. An example:

from pystac.extensions.file import FileExtension, MappingObject

FILE_SIZE = 100
VALUES = {
    1: "Temperate or sub-polar needleleaf forest",
    2: "Sub-polar taiga needleleaf forest",
    3: "Tropical or sub-tropical broadleaf evergreen forest",
...
}

values: List[MappingObject] = [
    MappingObject.create(values=[i], summary=s) for i, s in VALUES.items()
]

file_ext = FileExtension.ext(data_asset, add_if_missing=True)
file_ext.apply(size=FILE_SIZE, values=values)

results in

TypeError: Object of type MappingObject is not JSON serializable

when saving the STAC. The following change is a viable workaround:

values: List[Any] = [
    dict(values=[i], summary=s) for i, s in VALUES.items()
]
@jamesvrt jamesvrt changed the title MappingObject (extensions/Files) doesn't work for values MappingObject (extensions/Files) doesn't work Aug 13, 2021
@jamesvrt jamesvrt changed the title MappingObject (extensions/Files) doesn't work pystac.extensions.file.MappingObject doesn't work Aug 13, 2021
@lossyrob lossyrob added the bug Things which are broken label Jan 3, 2022
@lossyrob
Copy link
Member

lossyrob commented Jan 3, 2022

The fix is to make the values setter here "unbox" the MappingObject in a similar fashion as is done here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things which are broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants