From b84edf58787e4b3d0106c25988e9325adbb57771 Mon Sep 17 00:00:00 2001 From: Vsevolod Fedorov Date: Mon, 11 Jul 2022 12:49:03 +0300 Subject: [PATCH] ModuleError exception: Fix unresolved module name case When unable to resolve module_name due to frame=None, instead of exiting loop, frame.f_code.co_name fails with AttributeError because of frame=None. Change-Id: Iaea32952ecb7ad6de212bfc0bb518e438fc8177a --- jenkins_jobs/errors.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jenkins_jobs/errors.py b/jenkins_jobs/errors.py index 489c08a45..2df9fd31d 100644 --- a/jenkins_jobs/errors.py +++ b/jenkins_jobs/errors.py @@ -16,10 +16,12 @@ class JenkinsJobsException(Exception): class ModuleError(JenkinsJobsException): def get_module_name(self): frame = inspect.currentframe() - co_name = frame.f_code.co_name module_name = "" - while frame and co_name != "run": + while frame: # XML generation called via dispatch + co_name = frame.f_code.co_name + if co_name == "run": + break if co_name == "dispatch": data = frame.f_locals module_name = "%s.%s" % (data["component_type"], data["name"]) @@ -30,7 +32,6 @@ class ModuleError(JenkinsJobsException): module_name = next(iter(data.keys())) break frame = frame.f_back - co_name = frame.f_code.co_name return module_name