From 85e4a29af4ab8a5a6e5e20c363c37f45ffb646a4 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 30 Dec 2015 15:11:27 -0500 Subject: [PATCH] Allow struct API to work on missing data --- gramps/gen/lib/struct.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gramps/gen/lib/struct.py b/gramps/gen/lib/struct.py index 47a2852d9..95b471cb8 100644 --- a/gramps/gen/lib/struct.py +++ b/gramps/gen/lib/struct.py @@ -175,9 +175,11 @@ class Struct(object): # get first item in list that matches: sublist = [getattr(Struct(item, self.db), attr) for item in self.struct] return Struct(sublist, self.db) - else: + elif hasattr(self.struct, attr): # better be a property of the list/tuple/dict/value: return getattr(self.struct, attr) + else: + return Struct({}, self.db) # dummy, extending a previous dummy def __getitem__(self, item): """ @@ -221,7 +223,7 @@ class Struct(object): if obj: return Struct(obj.to_struct(), self.db) else: - raise AttributeError("missing object: %s" % item) + return Struct({}, self.db) # dummy, a db error elif isinstance(item, (list, tuple)): return Struct(item, self.db) elif isinstance(item, dict) and "_class" in item.keys():