Fix NameError in intelmqdump when loading global settings fails - #2723
Open
cristianchiriac wants to merge 1 commit into
Open
cristianchiriac wants to merge 1 commit into
cristianchiriac wants to merge 1 commit into
Conversation
Fixes certtools#2702. In an incomplete setup (dev install before running intelmqsetup, or a deleted runtime config), utils.get_global_settings() raises, but the except block only sets log_level and never assigns defaults. The very next line calls defaults.get(...), crashing with NameError instead of failing with the real underlying exception (or proceeding, if the failure was transient). Set defaults = {} in the except block, and add a regression test that runs main() with get_global_settings() forced to raise, asserting specifically that no NameError occurs. Note main() calls get_global_settings() again, unguarded, further down (to enumerate bots) — if the setup is genuinely and persistently broken, that call still legitimately fails; this fix only replaces the confusing NameError with the real, informative exception.
cristianchiriac
force-pushed
the
fix/intelmqdump-undefined-defaults
branch
from
September 17, 2026 11:00
f35eb8c to
dfd28f2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2702.
Bug
In
intelmq/bin/intelmqdump.py,main()tries to load global settings to determine the log level:If
get_global_settings()raises (incomplete setup, e.g. a dev install before runningintelmqsetup, or a deleted runtime config),defaultsis never assigned — but the very next block unconditionally callsdefaults.get(...), so instead of failing with the real, informative exception the tool crashes with a confusingNameError: name 'defaults' is not defined, exactly as described in the issue.Fix
Set
defaults = {}in theexceptblock, matching the fix suggested in the issue.Note:
main()callsget_global_settings()again, unguarded, further down (to enumerate bots and their dump locations). If the setup is genuinely and persistently broken, that second call still legitimately fails — this fix doesn't make the tool run without any config, it just replaces the confusing internalNameErrorwith the real underlying exception (or lets the tool proceed normally, if the first failure was transient).Test plan
test_incomplete_setup_does_not_raise_nameerror, mockingget_global_settingsto raise and asserting specifically thatmain()doesn't raiseNameError— any other exception from later inmain()(the genuinely-broken-setup case above) is expected and not what the test guards against.intelmqdump.pyimportsfcntland is Unix-only, and I don't have a Linux environment set up to run the full suite here) — reproduced the exactNameErrorfrom the unpatchedtry/exceptlogic, confirmed it's gone after the one-line fix.