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

Response models are not being used to validate responses #461

Closed
drnextgis opened this issue Sep 20, 2022 · 3 comments
Closed

Response models are not being used to validate responses #461

drnextgis opened this issue Sep 20, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@drnextgis
Copy link
Contributor

drnextgis commented Sep 20, 2022

I've got confused by the fact that response models are not being used to validate responses. Isn't that its main purpose? As you can see here for example response model is Collection. But if we modify collection's content in the database (pgstac) in order not to be align with the response model stac-fastapi simple ignores it and returns what we have in the database without any warning/error:

$ postgis=# UPDATE collections SET content = JSONB_SET(content, '{type}', '"MyCollection"');
$ curl -s -X 'GET' \
  'http://localhost:8082/collections/joplin' \
  -H 'accept: application/json' | jq '.type'
"MyCollection"

But according to the response model type should be Collection.

ENABLE_RESPONSE_MODELS set to true

@gadomski gadomski mentioned this issue Jan 31, 2023
4 tasks
@gadomski
Copy link
Member

I believe you're correct -- I've opened #519 to track the issue. Currently I just have a failing test to demonstrate the issue.

@gadomski gadomski added the bug Something isn't working label Jan 31, 2023
@gadomski gadomski self-assigned this Jan 31, 2023
@gadomski gadomski removed their assignment May 12, 2023
@drnextgis drnextgis mentioned this issue Apr 8, 2024
4 tasks
@vincentsarago
Copy link
Member

I confirmed this.

The thing was that we are using wrap_response to make sure the endpoints return a starlette Response, but this issue is then FastAPI will not run pydantic validation/serialization if the endpoint respond a Response object

def _wrap_response(resp: Any, response_class: Type[Response]) -> Response:
if isinstance(resp, Response):
return resp
elif resp is not None:
return response_class(resp)
else: # None is returned as 204 No Content
return Response(status_code=HTTP_204_NO_CONTENT)

I've changed this in thomas-maschler#2 for next stac-fastapi major version and will also change this for ~2.4 (maybe 2.5) #650 (comment)

@vincentsarago
Copy link
Member

I believe this is not fixed and tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants