Skip to content

⬆️ Bump Starlette to <0.53.0#14695

Closed
musicinmybrain wants to merge 1 commit intofastapi:masterfrom
musicinmybrain:starlette-0.51
Closed

⬆️ Bump Starlette to <0.53.0#14695
musicinmybrain wants to merge 1 commit intofastapi:masterfrom
musicinmybrain:starlette-0.51

Conversation

@musicinmybrain
Copy link
Contributor

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.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 11, 2026

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing musicinmybrain:starlette-0.51 (cd01810) with master (79406a4)

Open in CodSpeed

@github-actions
Copy link
Contributor

github-actions bot commented Jan 11, 2026

@jkugler
Copy link

jkugler commented Jan 19, 2026

@musicinmybrain
Copy link
Contributor Author

Could we get this bumped to <0.53 as 0.52.1 is out. https://github.com/Kludex/starlette/releases/tag/0.52.1

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).”

@musicinmybrain musicinmybrain changed the title ⬆️ Bump Starlette to <0.52.0 ⬆️ Bump Starlette to <0.53.0 Jan 20, 2026
@musicinmybrain
Copy link
Contributor Author

Updated to allow Starlette 0.52. All tests still pass.

@YuriiMotov
Copy link
Member

Failing CI should be resolved by #14756

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

This pull request has a merge conflict that needs to be resolved.

@github-actions github-actions bot removed the conflicts Automatically generated when a PR has a merge conflict label Feb 4, 2026
@galah92
Copy link

galah92 commented Feb 4, 2026

Will this allow using strict types for app.state?

@musicinmybrain
Copy link
Contributor Author

Will this allow using strict types for app.state?

I have no idea. I suppose you must be talking about the changes in https://github.com/Kludex/starlette/releases/tag/0.52.0.

@ollie-bell
Copy link

ollie-bell commented Feb 4, 2026

Will this allow using strict types for app.state?

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/

@Kludex
Copy link
Member

Kludex commented Feb 5, 2026

The above implies more changes are needed than just the bump. 😢

@galah92
Copy link

galah92 commented Feb 5, 2026

Will this allow using strict types for app.state?

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.

Thanks. Does this imply we need FastAPI changes to make it work, or further Starlette?

@Kludex
Copy link
Member

Kludex commented Feb 5, 2026

FastAPI.

@galah92
Copy link

galah92 commented Feb 5, 2026

FastAPI.

Thank you, I'll be happy to contribute this change once this PR is merged, if needed.

@edgarrmondragon
Copy link

With #14756 in and CI all green, is there anything else blocking this PR @YuriiMotov?

@antbz
Copy link

antbz commented Feb 6, 2026

Hi! Bumping this too, we need the updates to CORSMiddleware introduced in Starlette 0.51.0 and current constraints are blocking us from this.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

This pull request has a merge conflict that needs to be resolved.

@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Feb 6, 2026
@edgarrmondragon
Copy link

I guess this is now superseded by #14853

@tiangolo
Copy link
Member

tiangolo commented Feb 6, 2026

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. 🤓

@tiangolo tiangolo closed this Feb 6, 2026
@ollie-bell
Copy link

ollie-bell commented Feb 6, 2026

I fixed what is needed to support the latest Starlette version, and what is in git in the main branch in another PR. 🤓

@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.

@musicinmybrain
Copy link
Contributor Author

This was superseded by #14853, released in FastAPI 0.128.3 🎉

Thank you! The broader version range will be quite helpful for downstream packaging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically generated when a PR has a merge conflict upgrade

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants