Skip to content

Fix UnboundLocalError while recovering from an error#837

Open
mgedmin wants to merge 1 commit into
furlongm:mainfrom
mgedmin:fix-unbound-local-error
Open

Fix UnboundLocalError while recovering from an error#837
mgedmin wants to merge 1 commit into
furlongm:mainfrom
mgedmin:fix-unbound-local-error

Conversation

@mgedmin
Copy link
Copy Markdown

@mgedmin mgedmin commented Jun 1, 2026

See #690 (comment): 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

(This commit doesn't actually fix the processing error itself, you need a database schema fix for that -- drop the no-longer-used tags column from the hosts_host table.)

See furlongm#690 (comment):
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant