Skip to content

Commit 151348e

Browse files
committed
Check the handle is valid before trying to get the raw data
1 parent 2a4ab72 commit 151348e

File tree

1 file changed

+67
-14
lines changed

1 file changed

+67
-14
lines changed

gramps/plugins/lib/libmixin.py

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ class DbMixin:
6262
"""
6363

6464
def __find_primary_from_handle(
65-
self, handle, transaction, class_type, get_raw_obj_data, add_func
65+
self,
66+
handle,
67+
transaction,
68+
class_type,
69+
has_obj_handle,
70+
get_raw_obj_data,
71+
add_func,
6672
):
6773
"""
6874
Find a primary object of class_type in the database from the passed
@@ -77,8 +83,8 @@ def __find_primary_from_handle(
7783
obj = class_type()
7884
handle = str(handle)
7985
new = True
80-
raw = get_raw_obj_data(handle)
81-
if raw is not None:
86+
if has_obj_handle(handle):
87+
raw = get_raw_obj_data(handle)
8288
obj = data_to_object(raw)
8389
# references create object with id None before object is really made
8490
if obj.gramps_id is not None:
@@ -89,7 +95,13 @@ def __find_primary_from_handle(
8995
return obj, new
9096

9197
def __find_table_from_handle(
92-
self, handle, transaction, class_type, get_raw_obj_data, add_func
98+
self,
99+
handle,
100+
transaction,
101+
class_type,
102+
has_obj_handle,
103+
get_raw_obj_data,
104+
add_func,
93105
):
94106
"""
95107
Find a table object of class_type in the database from the passed
@@ -103,8 +115,8 @@ def __find_table_from_handle(
103115
"""
104116
obj = class_type()
105117
handle = str(handle)
106-
raw = get_raw_obj_data(handle)
107-
if raw is not None:
118+
if has_obj_handle(handle):
119+
raw = get_raw_obj_data(handle)
108120
obj = data_to_object(raw)
109121
return obj, False
110122
else:
@@ -154,7 +166,12 @@ def find_person_from_handle(self, handle, transaction):
154166
@rtype: tuple
155167
"""
156168
return self.__find_primary_from_handle(
157-
handle, transaction, Person, self.get_raw_person_data, self.add_person
169+
handle,
170+
transaction,
171+
Person,
172+
self.has_person_handle,
173+
self.get_raw_person_data,
174+
self.add_person,
158175
)
159176

160177
def find_source_from_handle(self, handle, transaction):
@@ -168,7 +185,12 @@ def find_source_from_handle(self, handle, transaction):
168185
@rtype: tuple
169186
"""
170187
return self.__find_primary_from_handle(
171-
handle, transaction, Source, self.get_raw_source_data, self.add_source
188+
handle,
189+
transaction,
190+
Source,
191+
self.has_source_handle,
192+
self.get_raw_source_data,
193+
self.add_source,
172194
)
173195

174196
def find_event_from_handle(self, handle, transaction):
@@ -182,7 +204,12 @@ def find_event_from_handle(self, handle, transaction):
182204
@rtype: tuple
183205
"""
184206
return self.__find_primary_from_handle(
185-
handle, transaction, Event, self.get_raw_event_data, self.add_event
207+
handle,
208+
transaction,
209+
Event,
210+
self.has_event_handle,
211+
self.get_raw_event_data,
212+
self.add_event,
186213
)
187214

188215
def find_object_from_handle(self, handle, transaction):
@@ -196,7 +223,12 @@ def find_object_from_handle(self, handle, transaction):
196223
@rtype: tuple
197224
"""
198225
return self.__find_primary_from_handle(
199-
handle, transaction, Media, self.get_raw_object_data, self.add_object
226+
handle,
227+
transaction,
228+
Media,
229+
self.has_object_handle,
230+
self.get_raw_object_data,
231+
self.add_object,
200232
)
201233

202234
def find_place_from_handle(self, handle, transaction):
@@ -210,7 +242,12 @@ def find_place_from_handle(self, handle, transaction):
210242
@rtype: tuple
211243
"""
212244
return self.__find_primary_from_handle(
213-
handle, transaction, Place, self.get_raw_place_data, self.add_place
245+
handle,
246+
transaction,
247+
Place,
248+
self.has_place_handle,
249+
self.get_raw_place_data,
250+
self.add_place,
214251
)
215252

216253
def find_family_from_handle(self, handle, transaction):
@@ -224,7 +261,12 @@ def find_family_from_handle(self, handle, transaction):
224261
@rtype: tuple
225262
"""
226263
return self.__find_primary_from_handle(
227-
handle, transaction, Family, self.get_raw_family_data, self.add_family
264+
handle,
265+
transaction,
266+
Family,
267+
self.has_family_handle,
268+
self.get_raw_family_data,
269+
self.add_family,
228270
)
229271

230272
def find_repository_from_handle(self, handle, transaction):
@@ -241,6 +283,7 @@ def find_repository_from_handle(self, handle, transaction):
241283
handle,
242284
transaction,
243285
Repository,
286+
self.has_repository_handle,
244287
self.get_raw_repository_data,
245288
self.add_repository,
246289
)
@@ -256,7 +299,12 @@ def find_note_from_handle(self, handle, transaction):
256299
@rtype: tuple
257300
"""
258301
return self.__find_primary_from_handle(
259-
handle, transaction, Note, self.get_raw_note_data, self.add_note
302+
handle,
303+
transaction,
304+
Note,
305+
self.has_note_handle,
306+
self.get_raw_note_data,
307+
self.add_note,
260308
)
261309

262310
def find_tag_from_handle(self, handle, transaction):
@@ -270,7 +318,12 @@ def find_tag_from_handle(self, handle, transaction):
270318
@rtype: tuple
271319
"""
272320
return self.__find_table_from_handle(
273-
handle, transaction, Tag, self.get_raw_tag_data, self.add_tag
321+
handle,
322+
transaction,
323+
Tag,
324+
self.has_tag_handle,
325+
self.get_raw_tag_data,
326+
self.add_tag,
274327
)
275328

276329
def check_person_from_handle(self, handle, transaction, set_gid=True):

0 commit comments

Comments
 (0)