From 012cb1ae744c2c5e819cce59b198c53ecbd306cb Mon Sep 17 00:00:00 2001 From: Pastukhov Nikita Date: Wed, 8 Jan 2025 16:53:06 +0300 Subject: [PATCH] fix (#2013): allow to create publisher in already connected broker (#2024) * fix: allow to create publisher in connected broker * chore: bump version --- faststream/__about__.py | 2 +- faststream/broker/core/usecase.py | 2 +- tests/brokers/base/publish.py | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/faststream/__about__.py b/faststream/__about__.py index 2c1ebe109b..cbfea67070 100644 --- a/faststream/__about__.py +++ b/faststream/__about__.py @@ -1,5 +1,5 @@ """Simple and fast framework to create message brokers based microservices.""" -__version__ = "0.5.33" +__version__ = "0.5.34" SERVICE_NAME = f"faststream-{__version__}" diff --git a/faststream/broker/core/usecase.py b/faststream/broker/core/usecase.py index 6da370b38d..4ad566ef45 100644 --- a/faststream/broker/core/usecase.py +++ b/faststream/broker/core/usecase.py @@ -285,7 +285,7 @@ def _publisher_setup_extra(self) -> "AnyDict": def publisher(self, *args: Any, **kwargs: Any) -> "PublisherProto[MsgType]": pub = super().publisher(*args, **kwargs) - if self.running: + if self.running or self._connection is not None: self.setup_publisher(pub) return pub diff --git a/tests/brokers/base/publish.py b/tests/brokers/base/publish.py index c94b9ca6bb..79c538a397 100644 --- a/tests/brokers/base/publish.py +++ b/tests/brokers/base/publish.py @@ -578,6 +578,12 @@ async def handler(m): assert event.is_set() assert not mock.called + @pytest.mark.asyncio + async def test_publisher_after_connect(self, queue: str): + async with self.patch_broker(self.get_broker()) as br: + # Should pass without error + await br.publisher(queue).publish(None) + @pytest.mark.asyncio async def test_publisher_after_start( self,