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

🐛 Fix response_model not invalidating None #2725

Merged
merged 5 commits into from Aug 22, 2022

Conversation

hukkin
Copy link
Contributor

@hukkin hukkin commented Jan 29, 2021

Related to #2719

@codecov
Copy link

codecov bot commented Jan 29, 2021

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
Contributor

📝 Docs preview for commit 2ba3e03 at: https://6014892c3c6551478a242c75--fastapi.netlify.app

@Kludex
Copy link
Sponsor Collaborator

Kludex commented Jan 29, 2021

I don't think this is going to be accepted. It introduces a breaking change. 😗

@ycd
Copy link
Contributor

ycd commented Jan 29, 2021

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
Contributor

📝 Docs preview for commit 0c7bd64 at: https://6303d11c7228b7149ae22e88--fastapi.netlify.app

@Kludex
Copy link
Sponsor Collaborator

Kludex commented Aug 22, 2022

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
Owner

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
Contributor

📝 Docs preview for commit 0eb4cef at: https://6303d4de86981b181826f072--fastapi.netlify.app

@tiangolo tiangolo merged commit 634cf22 into tiangolo: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: tiangolo/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: tiangolo/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: tiangolo/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: tiangolo/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.

None yet

5 participants