The Fix
pip install fastapi==0.128.4
Based on closed fastapi/fastapi issue #11580 · PR/commit linked
@@ -91,7 +91,7 @@ def __init__(
discriminator=discriminator,
multiple_of=multiple_of,
- allow_nan=allow_inf_nan,
+ allow_inf_nan=allow_inf_nan,
max_digits=max_digits,
import aiohttp
import asyncio
import math
import uvicorn
from fastapi import FastAPI, Query, Request, Response
from http import HTTPStatus
from typing import Annotated
app = FastAPI()
@app.get('/')
async def get(
x: Annotated[float | None, Query(gt=0, description='x')] = 1,
y: Annotated[float | None, Query(allow_inf_nan=False, description='y')] = 0) -> str:
assert x > 0
assert not math.isnan(y) and not math.isinf(y)
return 'OK'
async def main():
config = uvicorn.Config(app, host='127.0.0.1', port=8001)
server = uvicorn.Server(config)
task = asyncio.create_task(server.serve())
await asyncio.sleep(.1)
async with aiohttp.ClientSession() as session:
async with session.get('http://127.0.0.1:8001/?x=-1') as response:
assert response.status == HTTPStatus.UNPROCESSABLE_ENTITY
async with session.get('http://127.0.0.1:8001/?y=inf') as response:
assert response.status == HTTPStatus.UNPROCESSABLE_ENTITY
await server.shutdown()
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install fastapi==0.128.4\nWhen NOT to use: This fix should not be applied if backward compatibility with previous versions is required.\n\n
Why This Fix Works in Production
- Trigger: ERROR: Exception in ASGI application
- Mechanism: The allow_inf_nan parameter was ignored during parameter enforcement in FastAPI
- Why the fix works: Fixes the issue where the allow_inf_nan parameter was ignored during parameter enforcement in FastAPI. (first fixed release: 0.128.4).
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- Shows up under Python 3.10 in real deployments (not just unit tests).
- The allow_inf_nan parameter was ignored during parameter enforcement in FastAPI
- Surfaces as: INFO: Started server process [4301]
Proof / Evidence
- GitHub issue: #11580
- Fix PR: https://github.com/fastapi/fastapi/pull/11867
- First fixed release: 0.128.4
- Reproduced locally: No (not executed)
- Last verified: 2026-02-08
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.28
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“This should be solved by https://github.com/fastapi/fastapi/pull/11867, the fix will be available in FastAPI 0.112.2 released in the next few hours. :tada:”
“I made a PR for that at #11867 There was a little typo I suppose when passing the parameters to the pydantic object”
Failure Signature (Search String)
- ERROR: Exception in ASGI application
Error Message
Stack trace
Error Message
-------------
INFO: Started server process [4301]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8001 (Press CTRL+C to quit)
INFO: 127.0.0.1:58094 - "GET /?x=-1 HTTP/1.1" 422 Unprocessable Entity
INFO: 127.0.0.1:58094 - "GET /?y=inf HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/layer_svc/test/env/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/layer_svc/test/env/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
return await self.app(scope, receive, send)
File "/layer_svc/test/env/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/layer_svc/test/env/lib/python3.10/site-packages/starlette/applications.py", line 123, in __call__
await self.middleware_stack(scope, receive, send)
File "/layer_svc/test/env/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "/layer_svc/test/env/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "/layer_svc/test/env/lib/py
... (truncated) ...
Minimal Reproduction
import aiohttp
import asyncio
import math
import uvicorn
from fastapi import FastAPI, Query, Request, Response
from http import HTTPStatus
from typing import Annotated
app = FastAPI()
@app.get('/')
async def get(
x: Annotated[float | None, Query(gt=0, description='x')] = 1,
y: Annotated[float | None, Query(allow_inf_nan=False, description='y')] = 0) -> str:
assert x > 0
assert not math.isnan(y) and not math.isinf(y)
return 'OK'
async def main():
config = uvicorn.Config(app, host='127.0.0.1', port=8001)
server = uvicorn.Server(config)
task = asyncio.create_task(server.serve())
await asyncio.sleep(.1)
async with aiohttp.ClientSession() as session:
async with session.get('http://127.0.0.1:8001/?x=-1') as response:
assert response.status == HTTPStatus.UNPROCESSABLE_ENTITY
async with session.get('http://127.0.0.1:8001/?y=inf') as response:
assert response.status == HTTPStatus.UNPROCESSABLE_ENTITY
await server.shutdown()
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())
Environment
- Python: 3.10
What Broke
Numeric query fields accepted invalid inf and nan values, leading to unexpected behavior.
Why It Broke
The allow_inf_nan parameter was ignored during parameter enforcement in FastAPI
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install fastapi==0.128.4
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/fastapi/fastapi/pull/11867
First fixed release: 0.128.4
Last verified: 2026-02-08. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if backward compatibility with previous versions is required.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
- Pin production dependencies and upgrade only with a reproducible test that hits the failing path.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.128.4 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.