fixed mypy issues

This commit is contained in:
jasquat 2023-03-07 09:05:06 -05:00
parent d7f5e561d1
commit 2bb3e09c0d
No known key found for this signature in database
5 changed files with 31 additions and 10 deletions

View File

@ -11,5 +11,5 @@ class ScriptAttributesContext:
task: Optional[SpiffTask] task: Optional[SpiffTask]
environment_identifier: str environment_identifier: str
process_instance_id: int process_instance_id: Optional[int]
process_model_identifier: str process_model_identifier: Optional[str]

View File

@ -7,6 +7,7 @@ from spiffworkflow_backend.models.process_model import ProcessModelInfo
from spiffworkflow_backend.models.script_attributes_context import ( from spiffworkflow_backend.models.script_attributes_context import (
ScriptAttributesContext, ScriptAttributesContext,
) )
from spiffworkflow_backend.scripts.script import ProcessModelIdentifierMissingError
from spiffworkflow_backend.scripts.script import Script from spiffworkflow_backend.scripts.script import Script
@ -36,6 +37,12 @@ class GetMarkdownFileDownloadLink(Script):
digest = parts[2].split(",")[1][-64:] digest = parts[2].split(",")[1][-64:]
label = parts[1].split("=")[1] label = parts[1].split("=")[1]
process_model_identifier = script_attributes_context.process_model_identifier 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 = ( modified_process_model_identifier = (
ProcessModelInfo.modify_process_identifier_for_path_param( ProcessModelInfo.modify_process_identifier_for_path_param(
process_model_identifier process_model_identifier

View File

@ -8,6 +8,7 @@ from spiffworkflow_backend.models.process_instance_metadata import (
from spiffworkflow_backend.models.script_attributes_context import ( from spiffworkflow_backend.models.script_attributes_context import (
ScriptAttributesContext, ScriptAttributesContext,
) )
from spiffworkflow_backend.scripts.script import ProcessInstanceIdMissingError
from spiffworkflow_backend.scripts.script import Script from spiffworkflow_backend.scripts.script import Script
@ -26,6 +27,12 @@ class SaveProcessInstanceMetadata(Script):
) -> Any: ) -> Any:
"""Run.""" """Run."""
metadata_dict = args[0] 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(): for key, value in metadata_dict.items():
pim = ProcessInstanceMetadataModel.query.filter_by( pim = ProcessInstanceMetadataModel.query.filter_by(
process_instance_id=script_attributes_context.process_instance_id, process_instance_id=script_attributes_context.process_instance_id,

View File

@ -26,6 +26,14 @@ class ScriptUnauthorizedForUserError(Exception):
"""ScriptUnauthorizedForUserError.""" """ScriptUnauthorizedForUserError."""
class ProcessInstanceIdMissingError(Exception):
pass
class ProcessModelIdentifierMissingError(Exception):
pass
class Script: class Script:
"""Provides an abstract class that defines how scripts should work, this must be extended in all Script Tasks.""" """Provides an abstract class that defines how scripts should work, this must be extended in all Script Tasks."""

View File

@ -319,14 +319,13 @@ class CustomBpmnScriptEngine(PythonScriptEngine): # type: ignore
def __get_augment_methods(self, task: Optional[SpiffTask]) -> Dict[str, Callable]: def __get_augment_methods(self, task: Optional[SpiffTask]) -> Dict[str, Callable]:
"""__get_augment_methods.""" """__get_augment_methods."""
tld = current_app.config.get("THREAD_LOCAL_DATA") tld = current_app.config.get("THREAD_LOCAL_DATA")
if not hasattr(tld, "process_model_identifier"): process_model_identifier = None
process_model_identifier = None process_instance_id = None
else: if tld:
process_model_identifier = tld.process_model_identifier if hasattr(tld, "process_model_identifier"):
if not hasattr(tld, "process_instance_id"): process_model_identifier = tld.process_model_identifier
process_instance_id = None if hasattr(tld, "process_instance_id"):
else: process_instance_id = tld.process_instance_id
process_instance_id = tld.process_instance_id
script_attributes_context = ScriptAttributesContext( script_attributes_context = ScriptAttributesContext(
task=task, task=task,
environment_identifier=current_app.config["ENV_IDENTIFIER"], environment_identifier=current_app.config["ENV_IDENTIFIER"],