From 1a4e0c36e4fc0a5a6ca44a32c14046a312881368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 2 Jan 2024 17:13:22 +0100 Subject: [PATCH] Addon: gracefully handle disappearing job type When refreshing the list of available job types, Blender recreates the job type property itself, clearing out any previously chosen value. The add-on tries to restore that previously chosen value, and now also gracefully handles the case where this job type is no longer available. --- addon/flamenco/operators.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/addon/flamenco/operators.py b/addon/flamenco/operators.py index 40a87391..05de077d 100644 --- a/addon/flamenco/operators.py +++ b/addon/flamenco/operators.py @@ -76,8 +76,19 @@ class FLAMENCO_OT_fetch_job_types(FlamencoOpMixin, bpy.types.Operator): return {"CANCELLED"} if old_job_type_name: - # TODO: handle cases where the old job type no longer exists. - scene.flamenco_job_type = old_job_type_name + try: + scene.flamenco_job_type = old_job_type_name + except TypeError: # Thrown when the old job type no longer exists. + # You cannot un-set an enum property, and 'empty string' is not + # a valid value either, so better to just remove the underlying + # ID property. + del scene["flamenco_job_type"] + + self.report( + {"WARNING"}, + "Job type %r no longer available, choose another one" + % old_job_type_name, + ) job_types.update_job_type_properties(scene) return {"FINISHED"}