From 2f83a687871d56b564afb7f579e49b34f65f6ce8 Mon Sep 17 00:00:00 2001 From: jbirddog <100367399+jbirddog@users.noreply.github.com> Date: Thu, 21 Dec 2023 14:12:48 -0500 Subject: [PATCH] Clear caches when deleting a file (#826) --- .../routes/process_models_controller.py | 2 ++ .../services/spec_file_service.py | 10 +++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py index af96aaac..cce25159 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py @@ -16,6 +16,7 @@ from werkzeug.datastructures import FileStorage from spiffworkflow_backend.exceptions.api_error import ApiError from spiffworkflow_backend.interfaces import IdToProcessGroupMapping +from spiffworkflow_backend.models.db import db from spiffworkflow_backend.models.file import FileType from spiffworkflow_backend.models.process_group import ProcessGroup from spiffworkflow_backend.models.process_instance_report import ProcessInstanceReportModel @@ -258,6 +259,7 @@ def process_model_file_delete(modified_process_model_identifier: str, file_name: try: SpecFileService.delete_file(process_model, file_name) + db.session.commit() except FileNotFoundError as exception: raise ( ApiError( diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py index 476cb86d..b62c55a3 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py @@ -228,13 +228,9 @@ class SpecFileService(FileSystemService): full_file_path = SpecFileService.full_file_path(process_model, file_name) return FileSystemService._timestamp(full_file_path) - @staticmethod - def delete_file(process_model: ProcessModelInfo, file_name: str) -> None: - # Fixme: Remember to remove the lookup files when the process_model file is removed. - # lookup_files = session.query(LookupFileModel).filter_by(file_model_id=file_id).all() - # for lf in lookup_files: - # session.query(LookupDataModel).filter_by(lookup_file_model_id=lf.id).delete() - # session.query(LookupFileModel).filter_by(id=lf.id).delete() + @classmethod + def delete_file(cls, process_model: ProcessModelInfo, file_name: str) -> None: + cls.clear_caches_for_file(file_name, process_model) full_file_path = SpecFileService.full_file_path(process_model, file_name) os.remove(full_file_path)