Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

internal: enter lifespan

Myles Scolnickd9d0d09ac056
diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.py
index 2c750264fe..30639d5ea4 100644
--- a/marimo/_runtime/runtime.py
+++ b/marimo/_runtime/runtime.py
@@ -1938,6 +1938,9 @@ class Kernel:
During instantiation, UIElements can check for an initial value
with `get_initial_value`
"""
+ if self._lifespan is not None:
+ await self._lifespan.__aenter__()
+
self.load_dotenv()
if self.graph.cells:
diff --git a/marimo/_server/main.py b/marimo/_server/main.py
index cb729a939c..00fc47e1c8 100644
--- a/marimo/_server/main.py
+++ b/marimo/_server/main.py
@@ -90,8 +90,6 @@ def create_starlette_app(
]
)
- final_middlewares.extend(MIDDLEWARE_REGISTRY.get_all())
-
if lsp_servers is not None:
final_middlewares.extend(
_create_lsps_proxy_middleware(servers=lsp_servers)
@@ -100,6 +98,8 @@ def create_starlette_app(
if middleware:
final_middlewares.extend(middleware)
+ final_middlewares.extend(MIDDLEWARE_REGISTRY.get_all())
+
return Starlette(
routes=build_routes(base_url=base_url),
middleware=final_middlewares,