Skip to content

πŸ› Fix response_model not invalidating None - #2725

Merged
tiangolo merged 5 commits into
fastapi:masterfrom
hukkin:fix-invalid-none-response
Aug 22, 2022
Merged

tiangolo merged 5 commits into
fastapi:masterfrom
hukkin:fix-invalid-none-response

Conversation

@hukkin

@hukkin hukkin commented Jan 29, 2021 •

Copy link
Copy Markdown
Contributor

Related to #2719

@codecov

codecov Bot commented Jan 29, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #2725 (477b39b) into master (12f60ca) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #2725   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          533       533           
  Lines        13725     13746   +21     
=========================================
+ Hits         13725     13746   +21     
Impacted Files Coverage Ξ”
fastapi/utils.py 100.00% <ΓΈ> (ΓΈ)
tests/test_validate_response.py 100.00% <100.00%> (ΓΈ)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions

Copy link
Copy Markdown
Contributor

πŸ“ Docs preview for commit 2ba3e03 at: https://6014892c3c6551478a242c75--fastapi.netlify.app

@Kludex

Kludex commented Jan 29, 2021

Copy link
Copy Markdown
Contributor

I don't think this is going to be accepted. It introduces a breaking change. πŸ˜—

@ycd

ycd commented Jan 29, 2021

Copy link
Copy Markdown
Contributor

I agree with @Kludex, but this idea can be evaluated something like:

response_model_skip_validation: bool = False

By implementing something like this we can also be able to skip the response validation, and we will still have documentation for that object in our OpenAPI schema.

@tiangolo tiangolo changed the title Fix response_model not invalidating None πŸ› Fix response_model not invalidating None Aug 22, 2022
@github-actions

Copy link
Copy Markdown
Contributor

πŸ“ Docs preview for commit 0c7bd64 at: https://6303d11c7228b7149ae22e88--fastapi.netlify.app

@Kludex

Kludex commented Aug 22, 2022

Copy link
Copy Markdown
Contributor

I don't think this is going to be accepted. It introduces a breaking change. πŸ˜—

Oh me from the past, this comment is not very useful! Glad you learned over time! πŸ‘€

@tiangolo

Copy link
Copy Markdown
Member

Thanks for the contribution @hukkin! πŸš€

And thanks for the input @Kludex and @ycd! πŸ€“ I'll make sure I make a bump in the version as this will be a potentially breaking change.

This makes sense, as response_model should take anything that is a type annotation, and that Pydantic would receive in a field. Including a Union[Something, None]. And it also make sense that if the type annotation doesn't include None as a possible type, it should be a server error, the same it would be with a Pydantic field that doesn't allow a None type.

This will be available in FastAPI 0.80.0 πŸŽ‰

@tiangolo
tiangolo enabled auto-merge (squash) August 22, 2022 19:10
@github-actions

Copy link
Copy Markdown
Contributor

πŸ“ Docs preview for commit 0eb4cef at: https://6303d4de86981b181826f072--fastapi.netlify.app

@tiangolo
tiangolo merged commit 634cf22 into fastapi:master Aug 22, 2022
@hukkin
hukkin deleted the fix-invalid-none-response branch August 22, 2022 22:30
JenySadadia pushed a commit to JenySadadia/kernelci-api that referenced this pull request Mar 22, 2024
FastAPI doesn't validate `None` when handler has specified
a response model. Fix the below validation error for GET node by ID
and GET group by ID requests:
```
{"detail":"1 validation error for UserGroup\nresponse\n  none
is not an allowed value (type=type_error.none.not_allowed)"}
```
The change has been effective from `fastapi 0.80.0` version.
Reference: fastapi/fastapi#2725.

Signed-off-by: Jeny Sadadia <jeny.sadadia@collabora.com>
JenySadadia pushed a commit to JenySadadia/kernelci-api that referenced this pull request Mar 22, 2024
FastAPI doesn't validate `None` when handler has specified
a response model. Fix the below validation error for GET node by ID
and GET group by ID requests:
```
{"detail":"1 validation error for UserGroup\nresponse\n  none
is not an allowed value (type=type_error.none.not_allowed)"}
```
The change has been effective from `fastapi 0.80.0` version.
Reference: fastapi/fastapi#2725.

Signed-off-by: Jeny Sadadia <jeny.sadadia@collabora.com>
JenySadadia pushed a commit to JenySadadia/kernelci-api that referenced this pull request Mar 26, 2024
FastAPI doesn't validate `None` when handler has specified
a response model. Fix the below validation error for GET node by ID
and GET group by ID requests:
```
{"detail":"1 validation error for UserGroup\nresponse\n  none
is not an allowed value (type=type_error.none.not_allowed)"}
```
The change has been effective from `fastapi 0.80.0` version.
Reference: fastapi/fastapi#2725.

Signed-off-by: Jeny Sadadia <jeny.sadadia@collabora.com>
github-merge-queue Bot pushed a commit to kernelci/kernelci-api that referenced this pull request Apr 1, 2024
FastAPI doesn't validate `None` when handler has specified
a response model. Fix the below validation error for GET node by ID
and GET group by ID requests:
```
{"detail":"1 validation error for UserGroup\nresponse\n  none
is not an allowed value (type=type_error.none.not_allowed)"}
```
The change has been effective from `fastapi 0.80.0` version.
Reference: fastapi/fastapi#2725.

Signed-off-by: Jeny Sadadia <jeny.sadadia@collabora.com>
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.

5 participants