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
This commit is contained in:
Jaime van Kessel 2019-11-21 12:54:33 +01:00
parent 9aeb9912c8
commit fb4ce43f0c
No known key found for this signature in database
GPG key ID: 3710727397403C91
2 changed files with 9 additions and 1 deletions

View file

@ -7,6 +7,7 @@ from PyQt5.QtCore import Qt, QObject, pyqtProperty, pyqtSignal
import cura.CuraApplication import cura.CuraApplication
from UM.Qt.ListModel import ListModel from UM.Qt.ListModel import ListModel
from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Logger import Logger
from cura.Machines.ContainerTree import ContainerTree from cura.Machines.ContainerTree import ContainerTree
from cura.Machines.MaterialNode import MaterialNode from cura.Machines.MaterialNode import MaterialNode
from cura.Machines.Models.MachineModelUtils import fetchLayerHeight from cura.Machines.Models.MachineModelUtils import fetchLayerHeight
@ -101,6 +102,9 @@ class IntentModel(ListModel):
for extruder in global_stack.extruderList: for extruder in global_stack.extruderList:
active_variant_name = extruder.variant.getMetaDataEntry("name") 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_variant_node = machine_node.variants[active_variant_name]
active_material_node = active_variant_node.materials[extruder.material.getMetaDataEntry("base_file")] active_material_node = active_variant_node.materials[extruder.material.getMetaDataEntry("base_file")]
nodes.add(active_material_node) nodes.add(active_material_node)

View file

@ -39,7 +39,11 @@ class IntentManager(QObject):
# an empty list if nothing was found. # an empty list if nothing was found.
def intentMetadatas(self, definition_id: str, nozzle_name: str, material_base_file: str) -> List[Dict[str, Any]]: def intentMetadatas(self, definition_id: str, nozzle_name: str, material_base_file: str) -> List[Dict[str, Any]]:
intent_metadatas = [] # type: 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: if material_base_file not in materials:
return intent_metadatas return intent_metadatas