This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
OpenAPI page cannot load if Schema includes lt=inf [BUG] #1310
Comments
After further investigation, this could be a pydantic issue, as {
"properties": {
"myfloat": {
"exclusiveMaximum": inf,
"title": "Myfloat",
"type": "number"
}
},
"required": [
"myfloat"
],
"title": "MyModel",
"type": "object"
} The serialization is failing on the |
@vdwees i'd agree it's a pydantic issue. JSON does allow Infinity, and -Infinity as values, I don't know if those are swagger compliant tho. This is valid JSON
|
±Infinity (nor NaN) are definitely not valid JSON. |
@retnikt take a look at pydantic/pydantic#1417 Hope to have this issue fixed soon |
pydantic/pydantic#1422 was merged, should this issue be closed now, or should it wait for a pydantic release? |
Thanks for the discussion here everyone! ☕ I think we can close it here as it would be a Pydantic issue more than FastAPI. And whenever there's a new release, it will be available to be used with FastAPI as well. So I'm gonna close it now, but feel free to add more comments or new issues. |
7 months later, and this still seems to be a problem, i.e.: @router.get('/infinity')
def test_infinity():
return float('inf') still throws As far as I can tell, it looks like the pydantic PR was merged and is part of the current version (1.7.3), but I'm not familiar enough with FastAPI's internals to file a sensible bug elsewhere... any hints? |
@alex-r-bigelow I have the same problem, did you figure out a work-around? |
Not yet; for now I'm making deep copies of objects and manually converting any |
In my case this was because FastAPI was parsing the python object to JSON automatically. If I set the I guess FastAPI default parser will not allow illegal JSON values when parsing, who’d a thought it! |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
Pydantic allows inf, -inf values to be passed to a model. To exclude these, I used the
lt
param:The openapi page looks like this:
And on the server side, a runtime error:
This is a similar issue as #459, except that the invalid value is in the schema itself. The FastAPI.default_response_class is not used to serialize the openapi.json, and this IMO the correct behaviour, but it means the solution proposed in #459 does not apply here. As the model is used in other places outside of fastapi, it does not make sense to remove the
lt
kwarg.The text was updated successfully, but these errors were encountered: