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 #646

Closed
giorgiobasile opened this issue Mar 29, 2024 · 9 comments
Closed

Cannot use custom fields in Items #646

giorgiobasile opened this issue Mar 29, 2024 · 9 comments

Comments

@giorgiobasile
Copy link

giorgiobasile commented Mar 29, 2024

This issue follows: stac-utils/stac-fastapi-pgstac#93

In a nutshell, while trying to upload Items adhering to the Rendering extension using the POST /collection/{collection_id}/items API, I noticed that any additional custom field set at the Item level - not as a property - would be ignored by the transactional endpoints. This would basically hinder the ability to work with any extension that mandates the usage of additional fields at the Item level.

The payload I'm trying to use looks like:

{
    "type": "Feature",
    "stac_version": "1.0.0",
    "id": "nexgddp-storm-global-2080-rcp85",
    "properties": {...},
    "geometry": {...},
    "links": [...],
    "assets": {...},
    "bbox": [...],
    "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,
        }
    },
}

but the API responds with 200 OK and a similar Item, but without the renders object. The jsonb blob stored in the database doesn't have that field either.

With the help of @jonhealy1 we pinpointed the issue in this pydantic model, that does not allow for extra fields to be carried along during parsing happening in the transactional endpoints.

A potential solution would be to just specify:

class Item(TypedDict, total=False):
    """STAC Item."""
  
    model_config = ConfigDict(extra='allow')
  ...

and I'd be happy to send a PR, but I'm not sure whether that would actually solve the issue and what kinds of side-effects that could have, also for the other non-transactional endpoints. Any thoughts?

@jonhealy1
Copy link
Collaborator

Hi @giorgiobasile. I think the correct place to address this is actually in the extension itself. If you look here it says: "Additional attributes relating to an Item should be added into the Item Properties object, rather than directly in the Item object." The renders field should be inside the item properties I think.

@giorgiobasile
Copy link
Author

Hi @giorgiobasile. I think the correct place to address this is actually in the extension itself. If you look here it says: "Additional attributes relating to an Item should be added into the Item Properties object, rather than directly in the Item object." The renders field should be inside the item properties I think.

@jonhealy1 that's a great find, I understand. If you agree, I would consider the issue closed, and I'll open another one on the Rendering repo, to see whether they would consider changing it according to that recommendation.

Thank you again for helping out, appreciated!

@m-mohr
Copy link
Contributor

m-mohr commented Apr 5, 2024

I think renders should be in properties, not on the top-level. Feels more like an issue with the extension itself though: stac-extensions/render#4

@giorgiobasile
Copy link
Author

giorgiobasile commented Apr 5, 2024

Thanks @m-mohr, I would just also mention this section of the spec. According to the document, there would be the nesting issue to be considered if renders is a property, but not if it stays as a top-level object. But there are many factors to be considered, and you definitely know best!

@jonhealy1
Copy link
Collaborator

jonhealy1 commented Apr 5, 2024

Maybe renders can be flattened into a number of properties?

@giorgiobasile
Copy link
Author

giorgiobasile commented Apr 5, 2024

Maybe renders can be flattened into a number of properties?

The problem I see is that renders is a Map<string, Render>, so it supports multiple, arbitrary Render objects to be specified, so very difficult to flatten IMHO. But again, not really an expert, and maybe there is a reasonable way.

@m-mohr
Copy link
Contributor

m-mohr commented Apr 5, 2024

The nesting is only a niche issue for old GeoJSON tooling. Other extensions use nested maps without issues. The bigger issue is obviously to add top level properties to Items ;)

@vincentsarago
Copy link
Member

can we close this issue? is there anything that need fixing in stac-fastapi?

@giorgiobasile
Copy link
Author

can we close this issue? is there anything that need fixing in stac-fastapi?

Yes, no fix needed, the issue can be closed. Thanks everyone for helping out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants