diff --git a/bigchaindb/utils.py b/bigchaindb/utils.py index e89c3b6f..6ceace6b 100644 --- a/bigchaindb/utils.py +++ b/bigchaindb/utils.py @@ -180,8 +180,11 @@ class Lazy: def run(self, instance): last = instance - for method, (args, kwargs) in zip(self.stack[::2], self.stack[1::2]): - last = getattr(last, method)(*args, **kwargs) + for item in self.stack: + if isinstance(item, str): + last = getattr(last, item) + else: + last = last(*item[0], **item[1]) self.stack = [] return last diff --git a/tests/test_utils.py b/tests/test_utils.py index 47343ace..fbf5d65d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -141,7 +141,19 @@ def test_is_genesis_block_returns_true_if_genesis(b): def test_lazy_execution(): from bigchaindb.utils import Lazy + l = Lazy() l.split(',')[1].split(' ').pop(1).strip() result = l.run('Like humans, cats tend to favor one paw over another') assert result == 'cats' + + class Cat: + def __init__(self, name): + self.name = name + + cat = Cat('Shmui') + + l = Lazy() + l.name.upper() + result = l.run(cat) + assert result == 'SHMUI'