12510 review changes

This commit is contained in:
Arthur 2024-02-01 14:50:29 -08:00
parent da9b089723
commit 7e07136178
2 changed files with 16 additions and 20 deletions

View File

@ -513,7 +513,7 @@ class BaseScript:
return data
def run_tests(self, job):
def run_tests(self):
"""
Run the report and save its results. Each test method will be executed in order.
"""
@ -623,7 +623,7 @@ def run_script(data, job, request=None, commit=True, **kwargs):
raise AbortTransaction()
except AbortTransaction:
msg = _("Database changes have been reverted automatically.")
if is_report(script):
if is_report(type(script)):
# script and legacy reports have different log function signatures
script.log_info(message=msg)
else:
@ -640,7 +640,7 @@ def run_script(data, job, request=None, commit=True, **kwargs):
except Exception as e:
if type(e) is AbortScript:
msg = _("Script aborted with error: ") + str(e)
if is_report(script):
if is_report(type(script)):
script.log_failure(message=msg)
else:
script.log_failure(msg)
@ -649,13 +649,13 @@ def run_script(data, job, request=None, commit=True, **kwargs):
else:
stacktrace = traceback.format_exc()
msg = _("An exception occurred: : ") + f"`{type(e).__name__}: {e}`\n```\n{stacktrace}\n```"
if is_report(script):
if is_report(type(script)):
script.log_failure(message=msg)
else:
script.log_failure(msg)
logger.error(f"Exception raised during script execution: {e}")
msg = _("Database changes have been reverted due to error.")
if is_report(script):
if is_report(type(script)):
script.log_info(message=msg)
else:
script.log_info(msg)

View File

@ -47,6 +47,17 @@ def register_features(model, features):
registry['models'][app_label].add(model_name)
def is_script(obj):
"""
Returns True if the object is a Script.
"""
from .scripts import Script
try:
return issubclass(obj, Script) and obj != Script
except TypeError:
return False
def is_report(obj):
"""
Returns True if the given object is a Report.
@ -54,20 +65,5 @@ def is_report(obj):
from .reports import Report
try:
return issubclass(obj, Report) and obj != Report
except TypeError:
print("TypeError")
return False
def is_script(obj):
"""
Returns True if the object is a Script.
"""
# TODO: Deprecated legacy reports support
from .reports import Report
from .scripts import Script
try:
return ((issubclass(obj, Report) and obj != Report) or (issubclass(obj, Script) and obj != Script))
except TypeError:
return False