# Buggy code
def is_failover_possible(self, cluster, leader, candidate):
    if leader and (not cluster.leader or cluster.leader.name != leader):
        return "leader name does not match"
    if candidate:
        members = [m for m in cluster.members if m.name == candidate]
        if not members:
            return "candidate does not exists"
    else:
        members = [
            m for m in cluster.members if m.name != cluster.leader.name and m.api_url
        ]
        if not members:
            return (
                "failover is not possible: cluster does not have members except leader"
            )
    for _, reachable, _, _, tags in self.server.patroni.ha.fetch_nodes_statuses(
        members
    ):
        if reachable and not tags.get("nofailover", False):
            return None
    return "failover is not possible: no good candidates have been found"


# Traceback (ValueError)
Jul 28 12:35:31 postgres-5-2 patroni[1269]: 2017-07-28 12:35:31,258 INFO: received failover request with leader=postgres-5-2 candidate=postgres-5-3 scheduled_at=None
Jul 28 12:35:31 postgres-5-2 patroni[1269]: 2017-07-28 12:35:31,276 INFO: Got response from postgres-5-3 http://postgres-5-3:8008/patroni: b'{"role": "replica", "postmaster_start_time": "2017-07-28 12:31:09.295 UTC", "state": "running", "xlog": {"replayed_timestamp": "2017-07-28 12:31:09.208 UTC", "paused": false, "replayed_location": 369514424, "received_location": 369514424}, "server_version": 90603, "patroni": {"version": "1.3", "scope": "postgres-5"}, "database_system_identifier": "6447546693452231673"}'
Jul 28 12:35:31 postgres-5-2 patroni[1269]: 2017-07-28 12:35:31,367 INFO: Got response from postgres-5-3 http://postgres-5-3:8008/patroni: b'{"role": "replica", "postmaster_start_time": "2017-07-28 12:31:09.295 UTC", "state": "running", "xlog": {"replayed_timestamp": "2017-07-28 12:31:09.208 UTC", "paused": false, "replayed_location": 369514424, "received_location": 369514424}, "server_version": 90603, "patroni": {"version": "1.3", "scope": "postgres-5"}, "database_system_identifier": "6447546693452231673"}'
Jul 28 12:35:34 postgres-5-2 patroni[1269]: Traceback (most recent call last):
Jul 28 12:35:34 postgres-5-2 patroni[1269]: File "/usr/lib64/python3.4/socketserver.py", line 617, in process_request_thread
Jul 28 12:35:34 postgres-5-2 patroni[1269]: self.finish_request(request, client_address)
Jul 28 12:35:34 postgres-5-2 patroni[1269]: File "/usr/lib64/python3.4/socketserver.py", line 344, in finish_request
Jul 28 12:35:34 postgres-5-2 patroni[1269]: self.RequestHandlerClass(request, client_address, self)
Jul 28 12:35:34 postgres-5-2 patroni[1269]: File "/usr/lib64/python3.4/socketserver.py", line 673, in __init__
Jul 28 12:35:34 postgres-5-2 patroni[1269]: self.handle()
Jul 28 12:35:34 postgres-5-2 patroni[1269]: File "/usr/lib64/python3.4/http/server.py", line 401, in handle
Jul 28 12:35:34 postgres-5-2 patroni[1269]: self.handle_one_request()
Jul 28 12:35:34 postgres-5-2 patroni[1269]: File "/usr/lib64/python3.4/http/server.py", line 389, in handle_one_request
Jul 28 12:35:34 postgres-5-2 patroni[1269]: method()
Jul 28 12:35:34 postgres-5-2 patroni[1269]: File "/usr/lib/python3.4/site-packages/patroni/api.py", line 29, in wrapper
Jul 28 12:35:34 postgres-5-2 patroni[1269]: return func(handler)
Jul 28 12:35:34 postgres-5-2 patroni[1269]: File "/usr/lib/python3.4/site-packages/patroni/api.py", line 341, in do_POST_failover
Jul 28 12:35:34 postgres-5-2 patroni[1269]: data = self.is_failover_possible(cluster, leader, candidate)
Jul 28 12:35:34 postgres-5-2 patroni[1269]: File "/usr/lib/python3.4/site-packages/patroni/api.py", line 304, in is_failover_possible
Jul 28 12:35:34 postgres-5-2 patroni[1269]: for _, reachable, _, _, tags in self.server.patroni.ha.fetch_nodes_statuses(members):
Jul 28 12:35:34 postgres-5-2 patroni[1269]: ValueError: too many values to unpack (expected 5)

# Fixed code
def is_failover_possible(self, cluster, leader, candidate):
    if leader and (not cluster.leader or cluster.leader.name != leader):
        return "leader name does not match"
    if candidate:
        members = [m for m in cluster.members if m.name == candidate]
        if not members:
            return "candidate does not exists"
    else:
        members = [
            m for m in cluster.members if m.name != cluster.leader.name and m.api_url
        ]
        if not members:
            return (
                "failover is not possible: cluster does not have members except leader"
            )
    for st in self.server.patroni.ha.fetch_nodes_statuses(members):
        if st.failover_limitation() is None:
            return None
    return "failover is not possible: no good candidates have been found"