From 315b6d0cf139a708300f9b893b2055f9dda601c5 Mon Sep 17 00:00:00 2001 From: Ngo The Trung Date: Sat, 8 Apr 2017 00:46:27 +0800 Subject: [PATCH] Fix unorderable types error (#4409) If the updated datetime collides, the comparator of heapq will move onto the AuthorizationResource value and throws an "unorderable type" error. This adds an index value to the element tuple to ensure that they are always strictly ordered. --- acme/acme/client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/acme/acme/client.py b/acme/acme/client.py index 0c8886fc6..a069876d5 100644 --- a/acme/acme/client.py +++ b/acme/acme/client.py @@ -360,14 +360,18 @@ class Client(object): # pylint: disable=too-many-instance-attributes # priority queue with datetime.datetime (based on Retry-After) as key, # and original Authorization Resource as value - waiting = [(datetime.datetime.now(), authzr) for authzr in authzrs] + waiting = [ + (datetime.datetime.now(), index, authzr) + for index, authzr in enumerate(authzrs) + ] + heapq.heapify(waiting) # mapping between original Authorization Resource and the most # recently updated one updated = dict((authzr, authzr) for authzr in authzrs) while waiting: # find the smallest Retry-After, and sleep if necessary - when, authzr = heapq.heappop(waiting) + when, index, authzr = heapq.heappop(waiting) now = datetime.datetime.now() if when > now: seconds = (when - now).seconds @@ -386,7 +390,7 @@ class Client(object): # pylint: disable=too-many-instance-attributes if attempts[authzr] < max_attempts: # push back to the priority queue, with updated retry_after heapq.heappush(waiting, (self.retry_after( - response, default=mintime), authzr)) + response, default=mintime), index, authzr)) else: exhausted.add(authzr)