Blob Blame History Raw
From 255b85229b7395b7424a26eac0ab79fb813d596e Mon Sep 17 00:00:00 2001
From: Conor Stevenson <c.stevenson@outlook.com>
Date: Mon, 1 Jun 2020 22:23:05 +0100
Subject: [PATCH] set _connection in _ensure_connection (#1205)

Co-authored-by: Conor Stevenson <conor@lendingblock.com>
---
 kombu/connection.py       | 5 +++--
 t/unit/test_connection.py | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/kombu/connection.py b/kombu/connection.py
index 989a58682..5922c0187 100644
--- a/kombu/connection.py
+++ b/kombu/connection.py
@@ -434,12 +434,13 @@ def on_error(exc, intervals, retries, interval=0):
         if not reraise_as_library_errors:
             ctx = self._dummy_context
         with ctx():
-            return retry_over_time(
+            self._connection = retry_over_time(
                 self._connection_factory, self.recoverable_connection_errors,
                 (), {}, on_error, max_retries,
                 interval_start, interval_step, interval_max,
                 callback, timeout=timeout
             )
+            return self._connection
 
     @contextmanager
     def _reraise_as_library_errors(
@@ -860,7 +861,7 @@ def connection(self):
         if not self._closed:
             if not self.connected:
                 conn_opts = self._extract_failover_opts()
-                self._connection = self._ensure_connection(**conn_opts)
+                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 017dfae49..8a39855c6 100644
--- a/t/unit/test_connection.py
+++ b/t/unit/test_connection.py
@@ -131,7 +131,9 @@ def setup(self):
 
     def test_establish_connection(self):
         conn = self.conn
+        assert not conn.connected
         conn.connect()
+        assert conn.connected
         assert conn.connection.connected
         assert conn.host == 'localhost:5672'
         channel = conn.channel()