From df31de1c6e369f2f68a4330277196796b46b7ab2 Mon Sep 17 00:00:00 2001 From: Matus Valo Date: Sat, 23 May 2020 00:00:52 +0200 Subject: Fix broken compatibility with Celery --- kombu/connection.py | 24 +++++++++++++++++------- t/unit/test_connection.py | 8 ++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/kombu/connection.py b/kombu/connection.py index 64a49842..989a5868 100644 --- a/kombu/connection.py +++ b/kombu/connection.py @@ -280,7 +280,7 @@ class Connection(object): def connect(self): """Establish connection to server immediately.""" conn_opts = self._extract_failover_opts() - return self.ensure_connection(**conn_opts) + return self._ensure_connection(**conn_opts) def channel(self): """Create and return a new channel.""" @@ -380,10 +380,20 @@ class Connection(object): self._close() close = release - def ensure_connection(self, errback=None, max_retries=None, - interval_start=2, interval_step=2, interval_max=30, - callback=None, reraise_as_library_errors=True, - timeout=None): + def ensure_connection(self, *args, **kwargs): + """Public interface of _ensure_connection for retro-compatibility. + + Returns kombu.Connection instance. + """ + self._ensure_connection(*args, **kwargs) + return self + + def _ensure_connection( + self, errback=None, max_retries=None, + interval_start=2, interval_step=2, interval_max=30, + callback=None, reraise_as_library_errors=True, + timeout=None + ): """Ensure we have a connection to the server. If not retry establishing the connection with the settings @@ -533,7 +543,7 @@ class Connection(object): remaining_retries = None if max_retries is not None: remaining_retries = max(max_retries - retries, 1) - self.ensure_connection( + self._ensure_connection( errback, remaining_retries, interval_start, interval_step, interval_max, @@ -850,7 +860,7 @@ class Connection(object): if not self._closed: if not self.connected: conn_opts = self._extract_failover_opts() - self._connection = self.ensure_connection(**conn_opts) + self._connection = self._ensure_connection(**conn_opts) return self._connection def _connection_factory(self): diff --git a/t/unit/test_connection.py b/t/unit/test_connection.py index c4e3764c..017dfae4 100644 --- a/t/unit/test_connection.py +++ b/t/unit/test_connection.py @@ -144,10 +144,10 @@ class test_Connection: def test_connect_no_transport_options(self): conn = self.conn - conn.ensure_connection = Mock() + conn._ensure_connection = Mock() conn.connect() - conn.ensure_connection.assert_called_with() + conn._ensure_connection.assert_called_with() def test_connect_transport_options(self): conn = self.conn @@ -158,10 +158,10 @@ class test_Connection: 'interval_max': 4, 'ignore_this': True } - conn.ensure_connection = Mock() + conn._ensure_connection = Mock() conn.connect() - conn.ensure_connection.assert_called_with(**{ + conn._ensure_connection.assert_called_with(**{ k: v for k, v in options.items() if k in ['max_retries', 'interval_start', -- cgit v1.2.1