From 6598a8b9df9d388ab328cb7dbad272c360711282 Mon Sep 17 00:00:00 2001 From: "Gedminas, Marius" Date: Mon, 1 Jun 2026 09:30:36 +0300 Subject: [PATCH] Fix UnboundLocalError while recovering from an error See https://github.com/furlongm/patchman/issues/690#issuecomment-4574985291: if you upgrade a Patchman 3 setup to Patchman 4, the migrations don't correctly alter the hosts_host table and leave the tags column as NOT NULL, which then causes issues processing reports for previously unseen hosts. Host.objects.get_or_create() raises, the exception is caught and logged, and then subsequent `if host:` check fails with an UnboundLocalError: cannot access local variable 'host' where it is not associated with a value --- hosts/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hosts/utils.py b/hosts/utils.py index f8f89a15..bf6a1215 100644 --- a/hosts/utils.py +++ b/hosts/utils.py @@ -46,6 +46,7 @@ def get_or_create_host(report, arch, osvariant, domain): except herror: report.host = report.report_ip report.save() + host = None try: with transaction.atomic(): host, created = Host.objects.get_or_create(