diff --git a/crc/services/study_service.py b/crc/services/study_service.py index 795b954c..a939a67f 100644 --- a/crc/services/study_service.py +++ b/crc/services/study_service.py @@ -5,7 +5,7 @@ from SpiffWorkflow import WorkflowException from crc import db, session from crc.api.common import ApiError from crc.models.protocol_builder import ProtocolBuilderStudy, ProtocolBuilderStatus -from crc.models.stats import WorkflowStatsModel +from crc.models.stats import WorkflowStatsModel, TaskEventModel from crc.models.study import StudyModel, Study, Category, WorkflowMetadata from crc.models.workflow import WorkflowSpecCategoryModel, WorkflowModel, WorkflowSpecModel, WorkflowState, \ WorkflowStatus @@ -47,6 +47,7 @@ class StudyService(object): @staticmethod def delete_study(study_id): session.query(WorkflowStatsModel).filter_by(study_id=study_id).delete() + session.query(TaskEventModel).filter_by(study_id=study_id).delete() session.query(WorkflowModel).filter_by(study_id=study_id).delete() session.query(StudyModel).filter_by(id=study_id).delete() diff --git a/tests/test_study_api.py b/tests/test_study_api.py index 1f9c6bda..f7198966 100644 --- a/tests/test_study_api.py +++ b/tests/test_study_api.py @@ -6,7 +6,7 @@ from crc import session from crc.models.api_models import WorkflowApiSchema from crc.models.protocol_builder import ProtocolBuilderStatus, \ ProtocolBuilderStudySchema -from crc.models.stats import WorkflowStatsModel +from crc.models.stats import WorkflowStatsModel, TaskEventModel from crc.models.study import StudyModel, StudySchema from crc.models.workflow import WorkflowSpecModel, WorkflowSpecModelSchema, WorkflowModel, WorkflowStatus, \ WorkflowSpecCategoryModel @@ -190,6 +190,9 @@ class TestStudyApi(BaseTest): stats = WorkflowStatsModel(study_id=study.id, workflow_id=workflow.id) session.add(stats) session.commit() + stats2 = TaskEventModel(study_id=study.id, workflow_id=workflow.id, user_uid=self.users[0]['uid']) + session.add(stats2) + session.commit() rv = self.app.delete('/v1.0/study/%i' % study.id, headers=self.logged_in_headers()) self.assert_success(rv)