#19816: Capture additional logging under ScriptJob

This commit is contained in:
Jeremy Stretch 2025-08-13 15:19:39 -04:00
parent 9c96089cfb
commit ead8a03893

View File

@ -59,6 +59,7 @@ class ScriptJob(JobRunner):
else:
script.log_failure(msg)
logger.error(f"Script aborted with error: {e}")
self.logger.error(f"Script aborted with error: {e}")
else:
stacktrace = traceback.format_exc()
@ -66,9 +67,11 @@ class ScriptJob(JobRunner):
message=_("An exception occurred: ") + f"`{type(e).__name__}: {e}`\n```\n{stacktrace}\n```"
)
logger.error(f"Exception raised during script execution: {e}")
self.logger.error(f"Exception raised during script execution: {e}")
if type(e) is not AbortTransaction:
script.log_info(message=_("Database changes have been reverted due to error."))
self.logger.info("Database changes have been reverted due to error.")
# Clear all pending events. Job termination (including setting the status) is handled by the job framework.
if request:
@ -108,9 +111,11 @@ class ScriptJob(JobRunner):
# Execute the script. If commit is True, wrap it with the event_tracking context manager to ensure we process
# change logging, event rules, etc.
if commit:
self.logger.info("Executing script (commit enabled)")
with ExitStack() as stack:
for request_processor in registry['request_processors']:
stack.enter_context(request_processor(request))
self.run_script(script, request, data, commit)
else:
self.logger.warning("Executing script (commit disabled)")
self.run_script(script, request, data, commit)