From 53cce8849c8c3382844296ee235a8babce643f2e Mon Sep 17 00:00:00 2001 From: eivanov Date: Fri, 5 Jul 2013 12:47:04 +0300 Subject: [PATCH] TwistedChannel correctly handles multi-argument deferreds. Twisted deferreds expect a single argument, and the docstring of TwistedChannel says it will call them with a tuple in case the original callback receives more than one. This commit makes the comment true. --- pika/adapters/twisted_connection.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pika/adapters/twisted_connection.py b/pika/adapters/twisted_connection.py index 3c99d4517..1f0fd0155 100644 --- a/pika/adapters/twisted_connection.py +++ b/pika/adapters/twisted_connection.py @@ -147,7 +147,19 @@ def wrapped(*args, **kwargs): d = defer.Deferred() self.__calls.add(d) d.addCallback(self.__clear_call, d) - kwargs['callback'] = d.callback + + def single_argument(*args): + """ + Make sure that the deferred is called with a single argument. + In case the original callback fires with more than one, convert + to a tuple. + """ + if len(args) > 1: + d.callback(tuple(args)) + else: + d.callback(*args) + + kwargs['callback'] = single_argument try: method(*args, **kwargs)