Commit cff911e 1 parent 524af96 commit cff911e Copy full SHA for cff911e
File tree 1 file changed +12
-1
lines changed
faststream/broker/fastapi
1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1
1
import json
2
+ import warnings
2
3
from abc import abstractmethod
3
4
from contextlib import asynccontextmanager
4
5
from enum import Enum
@@ -165,6 +166,8 @@ def __init__(
165
166
self .contact = None
166
167
167
168
self .schema = None
169
+ # Flag to prevent double lifespan start
170
+ self ._lifespan_started = False
168
171
169
172
super ().__init__ (
170
173
prefix = prefix ,
@@ -316,7 +319,15 @@ async def start_broker_lifespan(
316
319
context = dict (maybe_context )
317
320
318
321
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
+ )
320
331
321
332
for h in self ._after_startup_hooks :
322
333
h_context = await h (app )
You can’t perform that action at this time.
0 commit comments