From fb4ce43f0cde76af3abed48376b0a9fb216b9be4 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 21 Nov 2019 12:54:33 +0100 Subject: [PATCH] Prevent crashes when a variant could not be found This should not happen, but we've seen some cases where it would cause a crash, usually when a previous upgrade did something a bit weird (in this specific case; a printer with an empty variant, whereas it should have a variant). Since any change that the user will make will ensure that the variant is no longer empty (eg; any selection of a variant will mean it's no longer empty) and that there is no way back, it should be pretty safe to ignore the situation as it will resolve itself eventually CURA-6992 --- cura/Machines/Models/IntentModel.py | 4 ++++ cura/Settings/IntentManager.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cura/Machines/Models/IntentModel.py b/cura/Machines/Models/IntentModel.py index f5560bc94e..986f28a826 100644 --- a/cura/Machines/Models/IntentModel.py +++ b/cura/Machines/Models/IntentModel.py @@ -7,6 +7,7 @@ from PyQt5.QtCore import Qt, QObject, pyqtProperty, pyqtSignal import cura.CuraApplication from UM.Qt.ListModel import ListModel from UM.Settings.ContainerRegistry import ContainerRegistry +from UM.Logger import Logger from cura.Machines.ContainerTree import ContainerTree from cura.Machines.MaterialNode import MaterialNode from cura.Machines.Models.MachineModelUtils import fetchLayerHeight @@ -101,6 +102,9 @@ class IntentModel(ListModel): for extruder in global_stack.extruderList: active_variant_name = extruder.variant.getMetaDataEntry("name") + if active_variant_name not in machine_node.variants: + Logger.log("w", "Could not find the variant %s", active_variant_name) + continue active_variant_node = machine_node.variants[active_variant_name] active_material_node = active_variant_node.materials[extruder.material.getMetaDataEntry("base_file")] nodes.add(active_material_node) diff --git a/cura/Settings/IntentManager.py b/cura/Settings/IntentManager.py index 732e22d1bd..5133b401b4 100644 --- a/cura/Settings/IntentManager.py +++ b/cura/Settings/IntentManager.py @@ -39,7 +39,11 @@ class IntentManager(QObject): # an empty list if nothing was found. def intentMetadatas(self, definition_id: str, nozzle_name: str, material_base_file: str) -> List[Dict[str, Any]]: intent_metadatas = [] # type: List[Dict[str, Any]] - materials = ContainerTree.getInstance().machines[definition_id].variants[nozzle_name].materials + try: + materials = ContainerTree.getInstance().machines[definition_id].variants[nozzle_name].materials + except KeyError: + Logger.log("w", "Unable to find the machine %s or the variant %s", definition_id, nozzle_name) + materials = {} if material_base_file not in materials: return intent_metadatas