From a0952df9fb7e6327aed5b565d962b5aa037b1776 Mon Sep 17 00:00:00 2001 From: Rodolphe Marques Date: Thu, 22 Dec 2016 14:30:19 +0100 Subject: [PATCH] fixed mongodb queries to return genesis block and last voted block --- bigchaindb/backend/mongodb/query.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bigchaindb/backend/mongodb/query.py b/bigchaindb/backend/mongodb/query.py index 369cb39d..bf7b7da7 100644 --- a/bigchaindb/backend/mongodb/query.py +++ b/bigchaindb/backend/mongodb/query.py @@ -133,8 +133,9 @@ def write_vote(conn, vote): @register_query(MongoDBConnection) def get_genesis_block(conn): - return conn.db['bigchain'].find_one({'block.transactions.0.operation' == - 'GENESIS'}) + return conn.db['bigchain'].find_one({ + 'block.transactions.0.operation': 'GENESIS' + }) @register_query(MongoDBConnection) @@ -142,7 +143,10 @@ def get_last_voted_block(conn, node_pubkey): last_voted = conn.db['votes']\ .find({'node_pubkey': node_pubkey}, sort=[('vote.timestamp', -1)]) - if not last_voted: + + # pymongo seems to return a cursor even if there are no results + # so we actually need to check the count + if last_voted.count() == 0: return get_genesis_block(conn) mapping = {v['vote']['previous_block']: v['vote']['voting_for_block']