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

Cannot use custom fields in Items #93

Closed
giorgiobasile opened this issue Mar 26, 2024 · 6 comments
Closed

Cannot use custom fields in Items #93

giorgiobasile opened this issue Mar 26, 2024 · 6 comments

Comments

@giorgiobasile
Copy link

giorgiobasile commented Mar 26, 2024

Hi, I'm trying to upload items adhering with STAC Rendering extension using the POST /collection/{collection_id}/items API.

The extension mandates the specification of a renders object for each Item as a custom key - not as a property - with information about the item rendering. While pystac is able to validate it and produce a well-formed JSON, the API seems to ignore the additional renders object.

The body I'm sending looks like:

{
    "type": "Feature",
    "stac_version": "1.0.0",
    "id": "nexgddp-storm-global-2080-rcp85",
    "properties": {
        "proj:epsg": 3857,
        "datetime": "2080-01-01T00:00:00Z"
    },
    "geometry": {
      ...
    },
    "links": [
       ...
    ],
    "assets": {
      ...
    },
    "bbox": [
        -180.0,
        -85.0511287798066,
        180.0,
        85.05112877980659
    ],
    "stac_extensions": [
        "https://stac-extensions.github.io/render/v1.0.0/schema.json"
    ],
    "renders": {
        "webmap": {
            "title": "Storm risk (2080, RCP8.5)",
            "colormap_name": "blues",
            "return_mask": true,
        }
    },
}

I get back 200 OK, and the same JSON but without renders.

I then tried adding other custom keys, unrelated to any extension - i.e. {'test': 'test'} but still got the same behavior. This looks to me like a bug, as the readme says:

PgSTAC stores all collection and item records as jsonb fields exactly as they come in allowing for any custom fields to be stored and retrieved transparently.

Are you able to reproduce it? Maybe there are other reasons why the endpoint behaves this way? Also, not sure whether this is actually regulated by downstream projects like stac-fastapi and pgstac.

Thanks in advance for any help!

@giorgiobasile giorgiobasile changed the title Items custom fields and STAC Rendering extension Cannot use custom fields in Items Mar 27, 2024
@giorgiobasile
Copy link
Author

giorgiobasile commented Mar 28, 2024

thanks a lot @jonhealy1 for pointing me to this!

I think it is sensible that there is no explicit "render" field, as it would be impossible to support all possible additional fields - whether coming from an extension or not.
At the same time, pydantic allows for extra fields to be kept in the model instance; so that they would survive serialization and de-serialization. I'm not sure whether using that configuration would be enough - and what side effects would bring. Any thoughts? Thanks again.

@jonhealy1
Copy link
Collaborator

jonhealy1 commented Mar 28, 2024

Hi I erased my comment because I was second-guessing myself but I was thinking that the issue arises here

@jonhealy1
Copy link
Collaborator

jonhealy1 commented Mar 29, 2024

@giorgiobasile Hi. Is your field being saved in Postgres after you add an item? I'm wondering if the field makes it to the database or if stac-fastapi is preventing it from even getting there? The field could be disappearing before it gets to the database or afterwards when the api returns a stac-fastapi type Item.

@giorgiobasile
Copy link
Author

giorgiobasile commented Mar 29, 2024

@giorgiobasile Hi. Is your field being saved in Postgres after you add an item? I'm wondering if the field makes it to the database or if stac-fastapi is preventing it from even getting there? The field could be disappearing before it gets to the database or afterwards when the api returns a stac-fastapi type Item.

Good point, I can confirm that the item in the DB doesn't have the renders object. So, the field is disappearing before it gets to the database.
I think I can also confirm that the pydantic model you shared before is the one used by stac-fastapi transactional endpoints to parse Items - see here. Then, it makes sense that custom fields are immediately lost.

@jonhealy1
Copy link
Collaborator

Maybe we should move this issue over to the stac-fastapi parent repository as I think it would be an issue in other backends like stac-fastapi-elasticsearch as well?

@giorgiobasile
Copy link
Author

Yes, I think all backends would be affected. Opened stac-utils/stac-fastapi#646, thanks again for helping out!

@giorgiobasile giorgiobasile closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2024
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

2 participants