Skip to content

Commit cff911e

Browse files
authored
build: add warning about manual lifespan_context (#1878)
1 parent 524af96 commit cff911e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

faststream/broker/fastapi/router.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import warnings
23
from abc import abstractmethod
34
from contextlib import asynccontextmanager
45
from enum import Enum
@@ -165,6 +166,8 @@ def __init__(
165166
self.contact = None
166167

167168
self.schema = None
169+
# Flag to prevent double lifespan start
170+
self._lifespan_started = False
168171

169172
super().__init__(
170173
prefix=prefix,
@@ -316,7 +319,15 @@ async def start_broker_lifespan(
316319
context = dict(maybe_context)
317320

318321
context.update({"broker": self.broker})
319-
await self.broker.start()
322+
323+
if not self._lifespan_started:
324+
await self.broker.start()
325+
self._lifespan_started = True
326+
else:
327+
warnings.warn(
328+
"Specifying 'lifespan_context' manually is no longer necessary with FastAPI >= 0.112.2.",
329+
stacklevel=2,
330+
)
320331

321332
for h in self._after_startup_hooks:
322333
h_context = await h(app)

0 commit comments

Comments
 (0)