handle the case where there is no data in db yet.
[monitor.git] / monitor / database / info / findbad.py
index f147a92..13132d1 100644 (file)
@@ -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):
@@ -79,12 +82,15 @@ class FindbadNodeRecord(Entity):
 class FindbadPCURecord(Entity):
        @classmethod
        def get_all_latest(cls):
-               fbsync = cls.get_by(hostname="global")
-               return cls.query.filter_by(round=fbsync.round)
+               fbsync = FindbadPCURecordSync.get_by(plc_pcuid=0)
+               if fbsync:
+                       return cls.query.filter_by(round=fbsync.round)
+               else:
+                       return []
 
        @classmethod
        def get_latest_by(cls, **kwargs):
-               fbsync = cls.get_by(hostname="global")
+               fbsync = FindbadPCURecordSync.get_by(plc_pcuid=0)
                kwargs['round'] = fbsync.round
                return cls.query.filter_by(**kwargs)
 # ACCOUNTING