diff mbox series

[2/2] toaster/orm/lsupdates: Improve error handling

Message ID 20260828213336.2038983-2-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 74d8b3ad3fe2ce43860819fbb934bbc70cc14b56
Headers show
Series [1/2] toaster/tests: Add and use wait_until_element_visible() | expand

Commit Message

Richard Purdie Aug. 28, 2026, 9:33 p.m. UTC
Recent layer index changes are causing a KeyError in this code. Rather
than crash and break everything, show a warning and move on, which unbreaks
everything else, just skipping the problematic distro entry.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 .../orm/management/commands/lsupdates.py      | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/lib/toaster/orm/management/commands/lsupdates.py b/lib/toaster/orm/management/commands/lsupdates.py
index 153b26f60a5..1f36906eeef 100644
--- a/lib/toaster/orm/management/commands/lsupdates.py
+++ b/lib/toaster/orm/management/commands/lsupdates.py
@@ -226,14 +226,18 @@  class Command(BaseCommand):
 
         total = len(index.distros)
         for i, id in enumerate(index.distros):
-            distro, created = Distro.objects.get_or_create(
-                name=index.distros[id].name,
-                layer_version=Layer_Version.objects.get(
-                    pk=li_layer_branch_id_to_toaster_lv_id[index.distros[id].layerbranch_id]))
-            distro.up_date = index.distros[id].updated
-            distro.name = index.distros[id].name
-            distro.description = index.distros[id].description
-            distro.save()
+            try:
+                distro, created = Distro.objects.get_or_create(
+                    name=index.distros[id].name,
+                    layer_version=Layer_Version.objects.get(
+                        pk=li_layer_branch_id_to_toaster_lv_id[index.distros[id].layerbranch_id]))
+                distro.up_date = index.distros[id].updated
+                distro.name = index.distros[id].name
+                distro.description = index.distros[id].description
+                distro.save()
+            except KeyError as e:
+                logger.warning("Couldn't process %s (%s)" % (i, repr(e)))
+                continue
             self.mini_progress("distros", i, total)
 
         # update machines