| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Merging this PR will not alter performance✅ 20 untouched benchmarks Comparing musicinmybrain:starlette-0.51 (cd01810) with master (79406a4) |
Sorry, something went wrong.
📝 Docs previewLast commit cd01810 at: https://992b0e89.fastapitiangolo.pages.dev |
Sorry, something went wrong.
|
Could we get this bumped to <0.53 as 0.52.1 is out. https://github.com/Kludex/starlette/releases/tag/0.52.1 |
Sorry, something went wrong.
Sure. It looks like 0.52.0 should be compatible, and just adds a new feature: “In this release, State can be accessed using dictionary-style syntax for improved type safety (https://github.com/Kludex/starlette/pull/3036).” |
Sorry, something went wrong.
|
Updated to allow Starlette 0.52. All tests still pass. |
Sorry, something went wrong.
|
This pull request has a merge conflict that needs to be resolved. |
Sorry, something went wrong.
|
Will this allow using strict types for app.state? |
Sorry, something went wrong.
I have no idea. I suppose you must be talking about the changes in https://github.com/Kludex/starlette/releases/tag/0.52.0. |
Sorry, something went wrong.
It does not seem to work... I took the Starlette docs example, converted it to use FastAPI and forced an installation of starlette==0.52.1. Have pasted the stack trace below. from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from typing import TypedDict
import httpx
from fastapi import FastAPI, Request
from fastapi.responses import PlainTextResponse
class State(TypedDict):
http_client: httpx.AsyncClient
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[State]:
async with httpx.AsyncClient() as client:
yield {"http_client": client}
app = FastAPI(lifespan=lifespan)
@app.get("/")
async def homepage(request: Request[State]) -> PlainTextResponse:
client = request.state["http_client"]
reveal_type(client) # Revealed type is 'httpx.AsyncClient'
response = await client.get("https://www.example.com")
return PlainTextResponse(response.text)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app=app)Traceback (most recent call last):
File "/Users/ollie/Documents/fastapi-lifespan-state-attribute-style.py", line 24, in <module>
@app.get("/")
~~~~~~~^^^^^
File "/Users/ollie/Documents/.venv/lib/python3.13/site-packages/fastapi/routing.py", line 1063, in decorator
self.add_api_route(
~~~~~~~~~~~~~~~~~~^
path,
^^^^^
...<23 lines>...
generate_unique_id_function=generate_unique_id_function,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/ollie/Documents/.venv/lib/python3.13/site-packages/fastapi/routing.py", line 1002, in add_api_route
route = route_class(
self.prefix + path,
...<24 lines>...
generate_unique_id_function=current_generate_unique_id,
)
File "/Users/ollie/Documents/.venv/lib/python3.13/site-packages/fastapi/routing.py", line 621, in __init__
self.dependant = get_dependant(
~~~~~~~~~~~~~^
path=self.path_format, call=self.endpoint, scope="function"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/ollie/Documents/.venv/lib/python3.13/site-packages/fastapi/dependencies/utils.py", line 281, in get_dependant
param_details = analyze_param(
param_name=param_name,
...<2 lines>...
is_path_param=is_path_param,
)
File "/Users/ollie/Documents/.venv/lib/python3.13/site-packages/fastapi/dependencies/utils.py", line 506, in analyze_param
field = create_model_field(
name=param_name,
...<4 lines>...
field_info=field_info,
)
File "/Users/ollie/Documents/.venv/lib/python3.13/site-packages/fastapi/utils.py", line 95, in create_model_field
raise fastapi.exceptions.FastAPIError(
_invalid_args_message.format(type_=type_)
) from None
fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that starlette.requests.Request[__main__.State] is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None. Read more: https://fastapi.tiangolo.com/tutorial/response-model/
|
Sorry, something went wrong.
|
The above implies more changes are needed than just the bump. 😢 |
Sorry, something went wrong.
Thanks. Does this imply we need FastAPI changes to make it work, or further Starlette? |
Sorry, something went wrong.
|
FastAPI. |
Sorry, something went wrong.
Thank you, I'll be happy to contribute this change once this PR is merged, if needed. |
Sorry, something went wrong.
|
With #14756 in and CI all green, is there anything else blocking this PR @YuriiMotov? |
Sorry, something went wrong.
|
Hi! Bumping this too, we need the updates to CORSMiddleware introduced in Starlette 0.51.0 and current constraints are blocking us from this. |
Sorry, something went wrong.
|
This pull request has a merge conflict that needs to be resolved. |
Sorry, something went wrong.
|
This was superseded by #14853, released in FastAPI 0.128.3 🎉 I fixed what is needed to support the latest Starlette version, and what is in git in the main branch in another PR. 🤓 |
Sorry, something went wrong.
@tiangolo Can I clarify if here you were referring to starlette 0.52.0+ Request with generic state type? I just tried 0.128.3 and the example shown above still errors in the same way. |
Sorry, something went wrong.
Thank you! The broader version range will be quite helpful for downstream packaging. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
In Starlette 0.51, the warning stacklevel on DeprecationWarning for the wsgi module was increased. There is no impact to FastAPI; all tests still pass.