Repository: pika/pika

Issue:
twisted channel _on_puback_message_returned has wrong number of args
_on_puback_message_returned in twisted channel has only 1 parameter, bug it's called with 4, is it a bug?

Discussion:

Patch:
diff --git a/pika/adapters/twisted_connection.py b/pika/adapters/twisted_connection.py
index ab90699..10c0ab8 100644
--- a/pika/adapters/twisted_connection.py
+++ b/pika/adapters/twisted_connection.py
@@ -736,7 +736,7 @@ class TwistedChannel(object):
                 else:
                     d.callback(method_frame.method)
 
-    def _on_puback_message_returned(self, message):
+    def _on_puback_message_returned(self, channel, method, properties, body):
         """Called as the result of Basic.Return from broker in
         publisher-acknowledgements mode. Saves the info as a ReturnedMessage
         instance in self._puback_return.
@@ -747,19 +747,18 @@ class TwistedChannel(object):
         :param bytes body: returned message body; empty string if no body
 
         """
-        assert isinstance(message.method, spec.Basic.Return), message.method
-        assert isinstance(message.properties,
-                          spec.BasicProperties), (message.properties)
+        assert isinstance(method, spec.Basic.Return), method
+        assert isinstance(properties, spec.BasicProperties), properties
 
         LOGGER.warning(
             "Published message was returned: _delivery_confirmation=%s; "
             "channel=%s; method=%r; properties=%r; body_size=%d; "
             "body_prefix=%.255r", self._delivery_confirmation,
-            message.channel.channel_number, message.method, message.properties,
-            len(message.body) if message.body is not None else None,
-            message.body)
+            channel.channel_number, method, properties,
+            len(body) if body is not None else None, body)
 
-        self._puback_return = message
+        self._puback_return = ReceivedMessage(channel=self,
+                method=method, properties=properties, body=body)
 
     def exchange_bind(self, destination, source, routing_key='',
                       arguments=None):


Test patch:
diff --git a/tests/acceptance/twisted_adapter_tests.py b/tests/acceptance/twisted_adapter_tests.py
index 4b6777f..38c989c 100644
--- a/tests/acceptance/twisted_adapter_tests.py
+++ b/tests/acceptance/twisted_adapter_tests.py
@@ -519,7 +519,7 @@ class TwistedChannelTestCase(TestCase):
             return d
 
         def check_response(error):
-            self.assertTrue(isinstance(error.value, NackError))
+            self.assertIsInstance(error.value, NackError)
             self.assertEqual(len(error.value.messages), 0)
         d.addCallback(send_message)
         d.addCallbacks(self.fail, check_response)
@@ -539,19 +539,15 @@ class TwistedChannelTestCase(TestCase):
             # Send the Basic.Return frame
             method = spec.Basic.Return(
                 exchange="testexch", routing_key="testrk")
-            return_cb(ReceivedMessage(
-                channel=self.channel,
-                method=method,
-                properties=spec.BasicProperties(),
-                body="testbody",
-            ))
+            return_cb(self.channel, method,
+                    spec.BasicProperties(), "testbody")
             # Send the Basic.Ack frame
             frame = Method(1, spec.Basic.Ack(delivery_tag=1))
             self.channel._on_delivery_confirmation(frame)
             return d
 
         def check_response(error):
-            self.assertTrue(isinstance(error.value, UnroutableError))
+            self.assertIsInstance(error.value, UnroutableError)
             self.assertEqual(len(error.value.messages), 1)
             msg = error.value.messages[0]
             self.assertEqual(msg.body, "testbody")
@@ -574,12 +570,8 @@ class TwistedChannelTestCase(TestCase):
             # Send the Basic.Return frame
             method = spec.Basic.Return(
                 exchange="testexch", routing_key="testrk")
-            return_cb(ReceivedMessage(
-                channel=self.channel,
-                method=method,
-                properties=spec.BasicProperties(),
-                body="testbody",
-            ))
+            return_cb(self.channel, method,
+                    spec.BasicProperties(), "testbody")
             # Send the Basic.Nack frame
             frame = Method(1, spec.Basic.Nack(delivery_tag=1))
             self.channel._on_delivery_confirmation(frame)