From 1a57bbcc24021a6c237cad6a26f5035f0fc8fa92 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 19 May 2017 10:50:06 +0200 Subject: [PATCH] etcd: fix acquire(blocking=True) on request exception If requests raises an exception and blocking is True, then there's no watch and nothing is returned. The problem is that then the reply variable is checked but it is actually not assigned, so a NameError is raised. This makes sure False is returned if an error occurs and blocking is True. Change-Id: I078826a894ee2cb8754259c8db9ea5ae19114910 --- tooz/drivers/etcd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tooz/drivers/etcd.py b/tooz/drivers/etcd.py index b121269..69b0647 100644 --- a/tooz/drivers/etcd.py +++ b/tooz/drivers/etcd.py @@ -131,7 +131,7 @@ class EtcdLock(locking.Lock): data={"ttl": self.ttl, "prevExist": "false"}) except requests.exceptions.RequestException: - if watch and watch.leftover() == 0: + if not watch or watch.leftover() == 0: return False # We got the lock! @@ -156,7 +156,7 @@ class EtcdLock(locking.Lock): make_url=False, timeout=watch.leftover() if watch else None) except requests.exceptions.RequestException: - if watch and watch.expired(): + if not watch or watch.expired(): return False @_translate_failures