Skip to content

Commit 3e1f826

Browse files
authored
added guards where we were getting exceptions (#4210)
* added guards where we were getting exceptions * added guards where we were getting exceptions * Used setdeafult for safe appending * Made update_color safer while I'm here
1 parent a088921 commit 3e1f826

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/windows/models/properties_model.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ def remove_keyframe(self, item):
195195
if not c:
196196
return
197197

198-
# Create reference
198+
# Create reference
199199
clip_data = c.data
200200
if object_id:
201201
clip_data = c.data.get('objects').get(object_id)
202-
202+
203203
if property_key in clip_data: # Update clip attribute
204204
log_id = "{}/{}".format(clip_id, object_id) if object_id else clip_id
205205
log.debug("%s: remove %s keyframe. %s", log_id, property_key, clip_data.get(property_key))
@@ -281,7 +281,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
281281
c = Effect.get(id=clip_id)
282282

283283
if c:
284-
# Create reference
284+
# Create reference
285285
clip_data = c.data
286286
if object_id:
287287
clip_data = c.data.get('objects').get(object_id)
@@ -301,7 +301,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
301301
# Keyframe
302302
# Loop through points, find a matching points on this frame
303303
found_point = False
304-
for point in clip_data[property_key][color]["Points"]:
304+
for point in clip_data[property_key][color].get("Points", []):
305305
log.debug("looping points: co.X = %s" % point["co"]["X"])
306306
if interpolation == -1 and point["co"]["X"] == self.frame_number:
307307
# Found point, Update value
@@ -348,7 +348,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
348348
if not found_point:
349349
clip_updated = True
350350
log.debug("Created new point at X=%d", self.frame_number)
351-
clip_data[property_key][color]["Points"].append({
351+
clip_data[property_key][color].setdefault("Points", []).append({
352352
'co': {'X': self.frame_number, 'Y': new_value},
353353
'interpolation': 1,
354354
})
@@ -357,7 +357,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
357357
clip_data = {property_key: clip_data[property_key]}
358358
if object_id:
359359
clip_data = {'objects': {object_id: clip_data}}
360-
360+
361361
# Save changes
362362
if clip_updated:
363363
# Save
@@ -430,8 +430,8 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
430430
c = Effect.get(id=clip_id)
431431

432432
if c:
433-
434-
# Create reference
433+
434+
# Create reference
435435
clip_data = c.data
436436
if object_id:
437437
clip_data = c.data.get('objects').get(object_id)
@@ -447,7 +447,7 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
447447
# Loop through points, find a matching points on this frame
448448
found_point = False
449449
point_to_delete = None
450-
for point in clip_data[property_key]["Points"]:
450+
for point in clip_data[property_key].get('Points', []):
451451
log.debug("looping points: co.X = %s" % point["co"]["X"])
452452
if interpolation == -1 and point["co"]["X"] == self.frame_number:
453453
# Found point, Update value
@@ -503,7 +503,7 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
503503
elif not found_point and new_value is not None:
504504
clip_updated = True
505505
log.debug("Created new point at X=%d", self.frame_number)
506-
clip_data[property_key]["Points"].append({
506+
clip_data[property_key].setdefault('Points', []).append({
507507
'co': {'X': self.frame_number, 'Y': new_value},
508508
'interpolation': 1})
509509

0 commit comments

Comments
 (0)