Skip to content

Conversation

@alukach
Copy link
Collaborator

@alukach alukach commented Nov 28, 2025

Related Issue(s):

Description:

Currently, the fields extension fails on the Collections endpoint due to the fact that we process the include and exclude arguments as set() values and then attempt to convert it to JSON. set values are not supported by json.dumps and thus an error is thrown.

This PR converts these values to a list before json.dumps().

Additionally, I have added a test to validate this behavior. #327 and #328 came out of these tests, requiring the testing to be adjusted slightly.

PR Checklist:

  • pre-commit hooks pass locally
  • Tests pass (run make test)
  • Documentation has been updated to reflect changes, if applicable, and docs build successfully (run make docs)
  • Changes are added to the CHANGELOG.

@alukach alukach force-pushed the bug/collection-fields-extension branch 2 times, most recently from e4c9d3c to 4aa6542 Compare November 28, 2025 16:50
@alukach alukach force-pushed the bug/collection-fields-extension branch from f0fbab4 to a915f2a Compare November 28, 2025 19:02
@alukach alukach force-pushed the bug/collection-fields-extension branch 3 times, most recently from 4b57864 to b5e71b4 Compare November 28, 2025 20:21
@alukach alukach force-pushed the bug/collection-fields-extension branch from b5e71b4 to 04600a3 Compare November 28, 2025 20:45
@alukach alukach marked this pull request as ready for review November 28, 2025 20:51
@alukach alukach force-pushed the bug/collection-fields-extension branch from d1df3ca to 4452922 Compare November 29, 2025 01:56
Copy link
Collaborator

@hrodmn hrodmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this @alukach!

resp_collections = resp_json["collections"]

assert len(resp_collections) > 0
# NOTE: It's a bug that 'collection' is always included; see #327
Copy link
Collaborator

@hrodmn hrodmn Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check to make sure this isn't coming from the pgstac side.

This comment was marked as outdated.

@vincentsarago

This comment was marked as off-topic.

includes.add(field)

base_args["fields"] = {"include": includes, "exclude": excludes}
base_args["fields"] = {"include": list(includes), "exclude": list(excludes)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI
The STAC Search model expects Sets https://github.com/stac-utils/stac-fastapi/blob/52a647af23af5dcb7d3c9a518f40db312bb4be5d/stac_fastapi/extensions/stac_fastapi/extensions/core/fields/request.py#L21-L23

When we call self._clean_search_args in the all_collections method we directly apply json.dumps() on the response but for other methods (e.g item_collection) we put it back within the Pydantic model

clean = self._clean_search_args(
base_args=base_args,
filter_query=filter_expr,
filter_lang=filter_lang,
fields=fields,
sortby=sortby,
**kwargs,
)
try:
search_request = self.pgstac_search_model(**clean)
except ValidationError as e:

Hopefully Pydantic is smart enough to convert back end list to a set

from stac_fastapi.api.models import create_post_request_model
from stac_fastapi.pgstac.types.search import PgstacSearch
from stac_fastapi.extensions.core import FieldsExtension

post_request_model = create_post_request_model([FieldsExtension()], base_model=PgstacSearch)

# Normal input (set)
post_request_model(fields={"include": {"yo"}}).fields
>> PostFieldsExtension(include={'yo'}, exclude=set())

# Input with this PR (list)
post_request_model(fields={"include": ["yo"]}).fields
>> PostFieldsExtension(include={'yo'}, exclude=set())

# Check output json (Pydantic transform set to list) 
post_request_model(fields={"include": {"yo"}}).model_dump_json()
>> '{"collections":null,"ids":null,"bbox":null,"intersects":null,"datetime":null,"limit":10,"conf":null,"fields":{"include":["yo"],"exclude":[]}}'

@alukach
Copy link
Collaborator Author

alukach commented Dec 1, 2025

Maybe I'm mistaken but there are no fields conformance class for collections (get_collections or get_collection) endpoint

Well I checked the PR and there is stac-api-extensions/fields#16 😓

but since we were supporting it, lets make it work 😅

I see you marked this comment as off-topic, but I will share that I was going off of: https://github.com/stac-api-extensions/collection-search/blob/v1.0.0-rc.1/README.md?plain=1#L103-L108

if fields:
return JSONResponse(collections) # type: ignore

return collections
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alukach @hrodmn added a passthrough to avoid Pydantic model validation when we have fields enabled (as we do for items)

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

Successfully merging this pull request may close these issues.

4 participants