diff --git a/src/Filters/Rules/Person/_HasCommonAncestorWith.py b/src/Filters/Rules/Person/_HasCommonAncestorWith.py
index ca4101168..1782ba868 100644
--- a/src/Filters/Rules/Person/_HasCommonAncestorWith.py
+++ b/src/Filters/Rules/Person/_HasCommonAncestorWith.py
@@ -57,11 +57,14 @@ class HasCommonAncestorWith(Rule):
         # Start with filling the cache for root person (gramps_id in self.list[0])
         self.ancestor_cache = {}
         root_person = db.get_person_from_gramps_id(self.list[0])
-        self.add_ancs(db, root_person)
-        self.with_people = [root_person.handle]
+        if root_person:
+            self.add_ancs(db, root_person)
+            self.with_people = [root_person.handle]
+        else:
+            self.with_people = []
 
     def add_ancs(self, db, person):
-        if person.handle not in self.ancestor_cache:
+        if person and person.handle not in self.ancestor_cache:
             self.ancestor_cache[person.handle] = set()
         else:
             return
@@ -85,13 +88,13 @@ class HasCommonAncestorWith(Rule):
         for handle in self.with_people:
             if ((handle in self.ancestor_cache and 
                  self.ancestor_cache[handle]) & 
-                (other.handle in self.ancestor_cache and 
+                (other and other.handle in self.ancestor_cache and 
                  self.ancestor_cache[other.handle])):
                 return True
         return False
 
     def apply(self, db, person):
-        if person.handle not in self.ancestor_cache:
+        if person and person.handle not in self.ancestor_cache:
             self.add_ancs(db, person)
 
         return self.has_common_ancestor(person)
diff --git a/src/Filters/Rules/Person/_HasCommonAncestorWithFilterMatch.py b/src/Filters/Rules/Person/_HasCommonAncestorWithFilterMatch.py
index 67166d172..5982bc830 100644
--- a/src/Filters/Rules/Person/_HasCommonAncestorWithFilterMatch.py
+++ b/src/Filters/Rules/Person/_HasCommonAncestorWithFilterMatch.py
@@ -51,8 +51,8 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith,MatchesFilter):
                     "with anybody matched by a filter")
     category    = _("Ancestral filters")
 
-    def __init__(self,list):
-        HasCommonAncestorWith.__init__(self,list)
+    def __init__(self, list):
+        HasCommonAncestorWith.__init__(self, list)
         self.ancestor_cache = {}
 
     def prepare(self, db):
@@ -67,7 +67,7 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith,MatchesFilter):
         filt.prepare(db)
         for handle in db.iter_person_handles():
             person = db.get_person_from_handle(handle)
-            if filt.apply (db, person):
+            if person and filt.apply(db, person):
                 #store all people in the filter so as to compare later
                 self.with_people.append(person.handle)
                 #fill list of ancestor of person if not present yet