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.
This commit is contained in:
Diego Prado Gesto 2018-12-11 11:37:01 +01:00
parent 0f357e1078
commit 2b2e8ebb31

View file

@ -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", ""),