From: Stephen Soltesz Date: Wed, 3 Dec 2008 19:06:59 +0000 (+0000) Subject: handle the case where there is no data in db yet. X-Git-Tag: Monitor-2.0-0~17 X-Git-Url: http://git.onelab.eu/?p=monitor.git;a=commitdiff_plain;h=9a3f616ba7f24ef6dd9b0de395ba7d997c273a13 handle the case where there is no data in db yet. --- diff --git a/monitor/database/info/findbad.py b/monitor/database/info/findbad.py index da7775a..13132d1 100644 --- a/monitor/database/info/findbad.py +++ b/monitor/database/info/findbad.py @@ -22,7 +22,10 @@ class FindbadNodeRecord(Entity): @classmethod def get_all_latest(cls): fbsync = FindbadNodeRecordSync.get_by(hostname="global") - return cls.query.filter_by(round=fbsync.round) + if fbsync: + return cls.query.filter_by(round=fbsync.round) + else: + return [] @classmethod def get_latest_by(cls, **kwargs): @@ -80,8 +83,10 @@ class FindbadPCURecord(Entity): @classmethod def get_all_latest(cls): fbsync = FindbadPCURecordSync.get_by(plc_pcuid=0) - print "round: ", fbsync.round - return cls.query.filter_by(round=fbsync.round) + if fbsync: + return cls.query.filter_by(round=fbsync.round) + else: + return [] @classmethod def get_latest_by(cls, **kwargs): diff --git a/monitor/wrapper/plc.py b/monitor/wrapper/plc.py index 2ddb061..255e3c1 100644 --- a/monitor/wrapper/plc.py +++ b/monitor/wrapper/plc.py @@ -15,7 +15,7 @@ import traceback from monitor import database try: - import config + from monitor import config debug = config.debug except: debug = False