From 2b2e8ebb31ffaacdcd6cac3851585de94af556c4 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Tue, 11 Dec 2018 11:37:01 +0100 Subject: [PATCH] Add some safety checks when checking for the guid of the material Don't crash if the guid doesn't exist. Contributes to CL-1160. --- .../UM3NetworkPrinting/src/ClusterUM3OutputDevice.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py index 60474156a8..d39cf6e41c 100644 --- a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py @@ -607,13 +607,18 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): def _createMaterialOutputModel(self, material_data: Dict[str, Any]) -> "MaterialOutputModel": material_manager = CuraApplication.getInstance().getMaterialManager() - material_group_list = material_manager.getMaterialGroupListByGUID(material_data["guid"]) + material_group_list = None + + # Avoid crashing if there is no "guid" field in the metadata + material_guid = material_data.get("guid") + if material_guid: + material_group_list = material_manager.getMaterialGroupListByGUID(material_guid) # This can happen if the connected machine has no material in one or more extruders (if GUID is empty), or the # material is unknown to Cura, so we should return an "empty" or "unknown" material model. if material_group_list is None: - material_name = "Empty" if len(material_data["guid"]) == 0 else "Unknown" - return MaterialOutputModel(guid = material_data["guid"], + material_name = "Empty" if len(material_data.get("guid", "") == 0 else "Unknown" + return MaterialOutputModel(guid = material_data.get("guid", ""), type = material_data.get("type", ""), color = material_data.get("color", ""), brand = material_data.get("brand", ""),