Clean up invalid quality changes robust to asynchronous changes

It's possible that a profile is no longer in the registry by the time it gets to that point in the list if this clean-up is triggered by the very action of deleting a profile.

Fixes Sentry issue CURA-1T5.
This commit is contained in:
Ghostkeeper 2021-03-16 16:36:01 +01:00
parent f4b417883e
commit 58369822fc
No known key found for this signature in database
GPG Key ID: 14C3586CD2EFC5B9

View File

@ -1,4 +1,4 @@
# Copyright (c) 2019 Ultimaker B.V.
# Copyright (c) 2021 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import os
@ -381,9 +381,10 @@ class CuraContainerRegistry(ContainerRegistry):
if profile_count > 1:
continue
# Only one profile found, this should not ever be the case, so that profile needs to be removed!
Logger.log("d", "Found an invalid quality_changes profile with the name %s. Going to remove that now", profile_name)
invalid_quality_changes = ContainerRegistry.getInstance().findContainersMetadata(name=profile_name)
self.removeContainer(invalid_quality_changes[0]["id"])
if invalid_quality_changes:
Logger.log("d", "Found an invalid quality_changes profile with the name %s. Going to remove that now", profile_name)
self.removeContainer(invalid_quality_changes[0]["id"])
@override(ContainerRegistry)
def _isMetadataValid(self, metadata: Optional[Dict[str, Any]]) -> bool: