From 2550a85bf00616cab4acbad8b3a5925635e06b8a Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Wed, 21 Oct 2026 20:22:00 +0200 Subject: [PATCH 1/3] Fix web apps failing to start with FastAPI 0.145+ and prepare 1.0.5 FastAPI 0.145 removed the deprecated `openapi_prefix` argument, which the `flet_web.fastapi.FastAPI` wrapper always forwarded, so `flet run --web`, the web browser view and FastAPI-hosted apps raised a `TypeError` on startup. The wrapper now maps `openapi_prefix` onto `root_path`, as FastAPI itself did before removing it (#6984). Backport of the `flet_fastapi.py` change from 77eace034 on flet-1.1.0. Bump the flet package to 1.0.5. --- CHANGELOG.md | 6 ++++++ client/pubspec.lock | 2 +- packages/flet/CHANGELOG.md | 4 ++++ packages/flet/pubspec.yaml | 2 +- .../packages/flet-web/src/flet_web/fastapi/flet_fastapi.py | 7 ++++--- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a78e4575d..a44c2ddfbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.0.5 + +### Bug fixes + +* Fix `flet run --web` and other Flet web apps failing to start with FastAPI 0.145 or later, which removed the `openapi_prefix` argument ([#6984](https://github.com/flet-dev/flet/issues/6984)) by @FeodorFitsner. + ## 1.0.4 ### Improvements diff --git a/client/pubspec.lock b/client/pubspec.lock index 7b9d48658c..8ce9cdf6a9 100644 --- a/client/pubspec.lock +++ b/client/pubspec.lock @@ -359,7 +359,7 @@ packages: path: "../packages/flet" relative: true source: path - version: "1.0.4" + version: "1.0.5" flet_ads: dependency: "direct main" description: diff --git a/packages/flet/CHANGELOG.md b/packages/flet/CHANGELOG.md index 5d91c0d3ec..1a7b2f066f 100644 --- a/packages/flet/CHANGELOG.md +++ b/packages/flet/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.5 + +_No changes in the `flet` Dart package; version bumped for release coordination with the fix for Flet web apps failing to start with FastAPI 0.145 or later ([#6984](https://github.com/flet-dev/flet/issues/6984))._ + ## 1.0.4 * Depend on `screen_brightness_platform_interface`, `screen_brightness_android` and `screen_brightness_ios` instead of `screen_brightness`, and drive `ScreenBrightnessService` through `ScreenBrightnessPlatform.instance`: apps embedding `flet` no longer register the Windows, macOS and OHOS `screen_brightness` plugins, whose Windows one talks to monitors over DDC/CI while the app runs ([#6629](https://github.com/flet-dev/flet/issues/6629), [#6493](https://github.com/flet-dev/flet/issues/6493), [#6925](https://github.com/flet-dev/flet/pull/6925)) by @ndonkoHenri. diff --git a/packages/flet/pubspec.yaml b/packages/flet/pubspec.yaml index 804175c48a..2fe0914987 100644 --- a/packages/flet/pubspec.yaml +++ b/packages/flet/pubspec.yaml @@ -2,7 +2,7 @@ name: flet description: Write entire Flutter app in Python or add server-driven UI experience into existing Flutter app. homepage: https://flet.dev repository: https://github.com/flet-dev/flet/tree/main/packages/flet -version: 1.0.4 +version: 1.0.5 # Supported platforms platforms: diff --git a/sdk/python/packages/flet-web/src/flet_web/fastapi/flet_fastapi.py b/sdk/python/packages/flet-web/src/flet_web/fastapi/flet_fastapi.py index cc8052c8c8..5f3272c2dc 100644 --- a/sdk/python/packages/flet-web/src/flet_web/fastapi/flet_fastapi.py +++ b/sdk/python/packages/flet-web/src/flet_web/fastapi/flet_fastapi.py @@ -15,6 +15,8 @@ import flet_web.fastapi +_DEFAULT_RESPONSE_CLASS = Default(JSONResponse) + class FastAPI(fastapi.FastAPI): """ @@ -38,7 +40,7 @@ def __init__( openapi_tags: Optional[list[dict[str, Any]]] = None, servers: Optional[list[dict[str, Union[str, Any]]]] = None, dependencies: Optional[Sequence[Depends]] = None, - default_response_class: type[Response] = Default(JSONResponse), + default_response_class: type[Response] = _DEFAULT_RESPONSE_CLASS, redirect_slashes: bool = True, docs_url: Optional[str] = "/docs", redoc_url: Optional[str] = "/redoc", @@ -139,8 +141,7 @@ async def lifespan(app: fastapi.FastAPI): terms_of_service=terms_of_service, contact=contact, license_info=license_info, - openapi_prefix=openapi_prefix, - root_path=root_path, + root_path=root_path or openapi_prefix, root_path_in_servers=root_path_in_servers, responses=responses, callbacks=callbacks, From 43018f94a0677877c3a943a294ebc521f2a14d92 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Wed, 21 Oct 2026 20:27:48 +0200 Subject: [PATCH 2/3] Test FastAPI wrapper root_path fallback and lifecycle hooks --- .../packages/flet-web/tests/test_fastapi.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 sdk/python/packages/flet-web/tests/test_fastapi.py diff --git a/sdk/python/packages/flet-web/tests/test_fastapi.py b/sdk/python/packages/flet-web/tests/test_fastapi.py new file mode 100644 index 0000000000..feb5865fc6 --- /dev/null +++ b/sdk/python/packages/flet-web/tests/test_fastapi.py @@ -0,0 +1,35 @@ +import pytest +from fastapi.testclient import TestClient + +from flet_web.fastapi import FastAPI + + +@pytest.mark.parametrize( + ("kwargs", "expected_root_path"), + [ + ({}, ""), + ({"root_path": "/app"}, "/app"), + ({"openapi_prefix": "/legacy"}, "/legacy"), + ({"openapi_prefix": "/legacy", "root_path": "/app"}, "/app"), + ], +) +def test_fastapi_root_path_and_lifecycle(kwargs, expected_root_path): + """`root_path` falls back to `openapi_prefix`, and lifecycle hooks run once.""" + events = [] + app = FastAPI( + **kwargs, + on_startup=[lambda: events.append("startup")], + on_shutdown=[lambda: events.append("shutdown")], + ) + + @app.get("/path") + def get_root_path(): + return {"root_path": app.root_path} + + with TestClient(app) as client: + assert events == ["startup"] + response = client.get("/path") + assert response.status_code == 200 + assert response.json() == {"root_path": expected_root_path} + + assert events == ["startup", "shutdown"] From 32590a8cd4a0a18acd49659e6c3c5b53f9eb160b Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Wed, 21 Oct 2026 20:30:21 +0200 Subject: [PATCH 3/3] Link PR in 1.0.5 changelogs --- CHANGELOG.md | 2 +- packages/flet/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a44c2ddfbe..f81535f987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Bug fixes -* Fix `flet run --web` and other Flet web apps failing to start with FastAPI 0.145 or later, which removed the `openapi_prefix` argument ([#6984](https://github.com/flet-dev/flet/issues/6984)) by @FeodorFitsner. +* Fix `flet run --web` and other Flet web apps failing to start with FastAPI 0.145 or later, which removed the `openapi_prefix` argument ([#6984](https://github.com/flet-dev/flet/issues/6984), [#6988](https://github.com/flet-dev/flet/pull/6988)) by @FeodorFitsner. ## 1.0.4 diff --git a/packages/flet/CHANGELOG.md b/packages/flet/CHANGELOG.md index 1a7b2f066f..7e08b78b24 100644 --- a/packages/flet/CHANGELOG.md +++ b/packages/flet/CHANGELOG.md @@ -1,6 +1,6 @@ ## 1.0.5 -_No changes in the `flet` Dart package; version bumped for release coordination with the fix for Flet web apps failing to start with FastAPI 0.145 or later ([#6984](https://github.com/flet-dev/flet/issues/6984))._ +_No changes in the `flet` Dart package; version bumped for release coordination with the fix for Flet web apps failing to start with FastAPI 0.145 or later ([#6984](https://github.com/flet-dev/flet/issues/6984), [#6988](https://github.com/flet-dev/flet/pull/6988))._ ## 1.0.4