File skip_wrong_collections_instead_crashing.patch of Package cobbler

Index: cobbler-3.3.3/cobbler/cobbler_collections/collection.py
===================================================================
--- cobbler-3.3.3.orig/cobbler/cobbler_collections/collection.py
+++ cobbler-3.3.3/cobbler/cobbler_collections/collection.py
@@ -198,8 +198,12 @@ class Collection:
         if _list is None:
             return
         for item_dict in _list:
-            item = self.factory_produce(self.api, item_dict)
-            self.add(item)
+            try:
+                item = self.factory_produce(self.api, item_dict)
+                self.add(item)
+            except Exception as exc:
+                self.logger.error(f"Error while loading a collection: {exc}. Skipping this collection!")
+
 
     def copy(self, ref, newname):
         """
Index: cobbler-3.3.3/cobbler/modules/serializers/file.py
===================================================================
--- cobbler-3.3.3.orig/cobbler/modules/serializers/file.py
+++ cobbler-3.3.3/cobbler/modules/serializers/file.py
@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fi
 import os
 import glob
 import json
+import logging
 
 import cobbler.api as capi
 from cobbler import settings
@@ -32,6 +33,8 @@ from cobbler.cexceptions import CX
 
 libpath = "/var/lib/cobbler/collections"
 
+logger = logging.getLogger()
+
 
 def register() -> str:
     """
@@ -154,7 +157,10 @@ def deserialize(collection, topological:
     datastruct = deserialize_raw(collection.collection_types())
     if topological and isinstance(datastruct, list):
         datastruct.sort(key=lambda x: x.get("depth", 1))
-    if isinstance(datastruct, dict):
-        collection.from_dict(datastruct)
-    elif isinstance(datastruct, list):
-        collection.from_list(datastruct)
+    try:
+        if isinstance(datastruct, dict):
+            collection.from_dict(datastruct)
+        elif isinstance(datastruct, list):
+            collection.from_list(datastruct)
+    except Exception as exc:
+        logger.error(f"Error while loading a collection: {exc}. Skipping this collection!")
Index: cobbler-3.3.3/cobbler/utils.py
===================================================================
--- cobbler-3.3.3.orig/cobbler/utils.py
+++ cobbler-3.3.3/cobbler/utils.py
@@ -686,8 +686,9 @@ def blender(api_handle, remove_dicts: bo
         for key in child_names:
             child = api_handle.find_items("", name=key, return_list=False)
             if child is None:
-                raise ValueError("Child with the name \"%s\" of parent object \"%s\" did not exist!"
+                logger.error("Child with the name \"%s\" did not exist! This child is referenced in consolidated object \"%s\"."
                                  % (key, root_obj.name))
+                continue
             results["children"][key] = child.to_dict()
 
     # sanitize output for koan and kernel option lines, etc

openSUSE Build Service is sponsored by