From cddf8de1af84694d339b2f1408eb122f3ee91d2c Mon Sep 17 00:00:00 2001 From: Nikita Pastukhov Date: Thu, 12 Dec 2024 07:26:39 +0300 Subject: [PATCH] fix: correct FastAPI with new state --- faststream/_internal/application.py | 17 +++++++++-------- faststream/_internal/fastapi/router.py | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/faststream/_internal/application.py b/faststream/_internal/application.py index 5f9c523797..4f670ffd85 100644 --- a/faststream/_internal/application.py +++ b/faststream/_internal/application.py @@ -16,9 +16,10 @@ from faststream._internal.constants import EMPTY from faststream._internal.context import ContextRepo from faststream._internal.log import logger -from faststream._internal.state import ( +from faststream._internal.state import DIState +from faststream._internal.state.application import ( + ApplicationState, BasicApplicationState, - DIState, RunningApplicationState, ) from faststream._internal.state.broker import OuterBrokerState @@ -103,7 +104,7 @@ def _init_setupable_( # noqa: PLW3201 serializer = PydanticSerializer() - self._state = BasicApplicationState( + self._state: ApplicationState = BasicApplicationState( di_state=DIState( use_fastdepends=True, get_dependent=None, @@ -171,6 +172,10 @@ def __init__( else: self.lifespan_context = fake_context + @property + def running(self) -> bool: + return self._state.running + @abstractmethod def exit(self) -> None: """Stop application manually.""" @@ -278,7 +283,7 @@ async def _shutdown_logging( "FastStream app shut down gracefully.", ) - # Setvice methods + # Service methods def _log(self, level: int, message: str) -> None: if self.logger is not None: @@ -328,7 +333,3 @@ def after_shutdown( apply_types(to_async(func), context__=self.context) ) return func - - @property - def running(self) -> bool: - return self._state.running diff --git a/faststream/_internal/fastapi/router.py b/faststream/_internal/fastapi/router.py index 8b2c8432fc..9451503045 100644 --- a/faststream/_internal/fastapi/router.py +++ b/faststream/_internal/fastapi/router.py @@ -235,7 +235,7 @@ def wrapper( response_model_exclude_defaults=response_model_exclude_defaults, response_model_exclude_none=response_model_exclude_none, provider_factory=self._get_dependencies_overides_provider, - state=self._state, + state=self._state.di_state, ) return wrapper