fixed mypy issues
This commit is contained in:
parent
d5800c5a40
commit
66e254a3b0
|
@ -11,5 +11,5 @@ class ScriptAttributesContext:
|
|||
|
||||
task: Optional[SpiffTask]
|
||||
environment_identifier: str
|
||||
process_instance_id: int
|
||||
process_model_identifier: str
|
||||
process_instance_id: Optional[int]
|
||||
process_model_identifier: Optional[str]
|
||||
|
|
|
@ -7,6 +7,7 @@ from spiffworkflow_backend.models.process_model import ProcessModelInfo
|
|||
from spiffworkflow_backend.models.script_attributes_context import (
|
||||
ScriptAttributesContext,
|
||||
)
|
||||
from spiffworkflow_backend.scripts.script import ProcessModelIdentifierMissingError
|
||||
from spiffworkflow_backend.scripts.script import Script
|
||||
|
||||
|
||||
|
@ -36,6 +37,12 @@ class GetMarkdownFileDownloadLink(Script):
|
|||
digest = parts[2].split(",")[1][-64:]
|
||||
label = parts[1].split("=")[1]
|
||||
process_model_identifier = script_attributes_context.process_model_identifier
|
||||
if process_model_identifier is None:
|
||||
raise ProcessModelIdentifierMissingError(
|
||||
"The process model identifier was not given to script"
|
||||
" 'markdown_file_download_link'. This script needs to be run from"
|
||||
" within the context of a process model."
|
||||
)
|
||||
modified_process_model_identifier = (
|
||||
ProcessModelInfo.modify_process_identifier_for_path_param(
|
||||
process_model_identifier
|
||||
|
|
|
@ -8,6 +8,7 @@ from spiffworkflow_backend.models.process_instance_metadata import (
|
|||
from spiffworkflow_backend.models.script_attributes_context import (
|
||||
ScriptAttributesContext,
|
||||
)
|
||||
from spiffworkflow_backend.scripts.script import ProcessInstanceIdMissingError
|
||||
from spiffworkflow_backend.scripts.script import Script
|
||||
|
||||
|
||||
|
@ -26,6 +27,12 @@ class SaveProcessInstanceMetadata(Script):
|
|||
) -> Any:
|
||||
"""Run."""
|
||||
metadata_dict = args[0]
|
||||
if script_attributes_context.process_instance_id is None:
|
||||
raise ProcessInstanceIdMissingError(
|
||||
"The process instance id was not given to script"
|
||||
" 'save_process_instance_metadata'. This script needs to be run from"
|
||||
" within the context of a process instance."
|
||||
)
|
||||
for key, value in metadata_dict.items():
|
||||
pim = ProcessInstanceMetadataModel.query.filter_by(
|
||||
process_instance_id=script_attributes_context.process_instance_id,
|
||||
|
|
|
@ -26,6 +26,14 @@ class ScriptUnauthorizedForUserError(Exception):
|
|||
"""ScriptUnauthorizedForUserError."""
|
||||
|
||||
|
||||
class ProcessInstanceIdMissingError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ProcessModelIdentifierMissingError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class Script:
|
||||
"""Provides an abstract class that defines how scripts should work, this must be extended in all Script Tasks."""
|
||||
|
||||
|
|
|
@ -319,14 +319,13 @@ class CustomBpmnScriptEngine(PythonScriptEngine): # type: ignore
|
|||
def __get_augment_methods(self, task: Optional[SpiffTask]) -> Dict[str, Callable]:
|
||||
"""__get_augment_methods."""
|
||||
tld = current_app.config.get("THREAD_LOCAL_DATA")
|
||||
if not hasattr(tld, "process_model_identifier"):
|
||||
process_model_identifier = None
|
||||
else:
|
||||
process_model_identifier = tld.process_model_identifier
|
||||
if not hasattr(tld, "process_instance_id"):
|
||||
process_instance_id = None
|
||||
else:
|
||||
process_instance_id = tld.process_instance_id
|
||||
process_model_identifier = None
|
||||
process_instance_id = None
|
||||
if tld:
|
||||
if hasattr(tld, "process_model_identifier"):
|
||||
process_model_identifier = tld.process_model_identifier
|
||||
if hasattr(tld, "process_instance_id"):
|
||||
process_instance_id = tld.process_instance_id
|
||||
script_attributes_context = ScriptAttributesContext(
|
||||
task=task,
|
||||
environment_identifier=current_app.config["ENV_IDENTIFIER"],
|
||||
|
|
Loading…
Reference in New Issue