From 3993297360433946c92c5a9a07e920913eac6844 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 10 Feb 2022 18:19:57 -0500 Subject: [PATCH] minor fixes to the study api to get things working locally when we pull down a database from testing. --- crc/api/study.py | 4 ++-- crc/models/study.py | 2 ++ crc/services/study_service.py | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crc/api/study.py b/crc/api/study.py index 5abd1efd..5ff2d743 100644 --- a/crc/api/study.py +++ b/crc/api/study.py @@ -42,7 +42,7 @@ def add_study(body): session.commit() master_workflow_results = __run_master_spec(study_model, spec_service.master_spec) - study = StudyService().get_study(study_model.id, categories, master_workflow_results) + study = StudyService().get_study(study_model.id, categories, master_workflow_results=master_workflow_results) study_data = StudySchema().dump(study) study_data["errors"] = ApiErrorSchema(many=True).dump(errors) return study_data @@ -103,7 +103,7 @@ def get_study(study_id, update_status=False): if update_status: study_model = session.query(StudyModel).filter(StudyModel.id == study_id).first() master_workflow_results = __run_master_spec(study_model, spec_service.master_spec) - study = StudyService().get_study(study_id, categories, master_workflow_results) + study = StudyService().get_study(study_id, categories, master_workflow_results=master_workflow_results) if (study is None): raise ApiError("unknown_study", 'The study "' + study_id + '" is not recognized.', status_code=404) return StudySchema().dump(study) diff --git a/crc/models/study.py b/crc/models/study.py index eebe26f9..5b5fc008 100644 --- a/crc/models/study.py +++ b/crc/models/study.py @@ -211,6 +211,8 @@ class Study(object): @classmethod def from_model(cls, study_model: StudyModel): + if not isinstance(study_model, StudyModel): + raise ApiError("Please don't call me with something other than StudyModel") if study_model is not None and len(study_model.__dict__.items()) > 0: args = dict((k, v) for k, v in study_model.__dict__.items() if not k.startswith('_')) args['events_history'] = study_model.events_history # For some reason this attribute is not picked up diff --git a/crc/services/study_service.py b/crc/services/study_service.py index 66d66a65..f1df7f2d 100755 --- a/crc/services/study_service.py +++ b/crc/services/study_service.py @@ -57,7 +57,7 @@ class StudyService(object): studies = [] for study_model in db_studies: if include_invalid or self._is_valid_study(study_model.id): - studies.append(StudyService.get_study(study_model.id, categories, study_model)) + studies.append(StudyService.get_study(study_model.id, categories, study_model=study_model)) return studies @staticmethod @@ -380,7 +380,9 @@ class StudyService(object): for pb_study in pb_studies: new_status = None new_progress_status = None - db_study = next((s for s in db_studies if s.id == pb_study.STUDYID), None) + db_study = session.query(StudyModel).filter(StudyModel.id == pb_study.STUDYID).first() + #db_study = next((s for s in db_studies if s.id == pb_study.STUDYID), None) + if not db_study: db_study = StudyModel(id=pb_study.STUDYID) db_study.status = None # Force a new sa