diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/markdown_file_download_link.py b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/markdown_file_download_link.py index de1c16c86..1a60c4074 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/markdown_file_download_link.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/markdown_file_download_link.py @@ -7,7 +7,6 @@ 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 @@ -38,10 +37,8 @@ class GetMarkdownFileDownloadLink(Script): 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." + raise self.get_proces_model_identifier_is_missing_error( + "markdown_file_download_link" ) modified_process_model_identifier = ( ProcessModelInfo.modify_process_identifier_for_path_param( @@ -49,6 +46,10 @@ class GetMarkdownFileDownloadLink(Script): ) ) process_instance_id = script_attributes_context.process_instance_id + if process_instance_id is None: + raise self.get_proces_instance_id_is_missing_error( + "save_process_instance_metadata" + ) url = current_app.config["SPIFFWORKFLOW_BACKEND_URL"] url += ( f"/v1.0/process-data-file-download/{modified_process_model_identifier}/" diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/save_process_instance_metadata.py b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/save_process_instance_metadata.py index 52bd7b381..19cb34fd3 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/save_process_instance_metadata.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/save_process_instance_metadata.py @@ -8,7 +8,6 @@ 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 @@ -28,10 +27,8 @@ class SaveProcessInstanceMetadata(Script): """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." + raise self.get_proces_instance_id_is_missing_error( + "save_process_instance_metadata" ) for key, value in metadata_dict.items(): pim = ProcessInstanceMetadataModel.query.filter_by( diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/script.py b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/script.py index 337c67ee4..12b7fdc7e 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/script.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/script.py @@ -57,6 +57,26 @@ class Script: + "does not properly implement the run function.", ) + def get_proces_instance_id_is_missing_error( + self, script_name: str + ) -> ProcessInstanceIdMissingError: + """Return the error so we can raise it from the script and mypy will be happy.""" + raise ProcessInstanceIdMissingError( + "The process instance id was not given to script" + f" '{script_name}'. This script needs to be run from" + " within the context of a process instance." + ) + + def get_proces_model_identifier_is_missing_error( + self, script_name: str + ) -> ProcessModelIdentifierMissingError: + """Return the error so we can raise it from the script and mypy will be happy.""" + return ProcessModelIdentifierMissingError( + "The process model identifier was not given to script" + f" '{script_name}'. This script needs to be run from" + " within the context of a process model." + ) + @staticmethod def requires_privileged_permissions() -> bool: """It seems safer to default to True and make safe functions opt in for any user to run them.