minor fixes to the study api to get things working locally when we pull down a database from testing.

This commit is contained in:
Dan 2022-02-10 18:19:57 -05:00
parent 1858cd314f
commit 3993297360
3 changed files with 8 additions and 4 deletions

View File

@ -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)

View File

@ -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

View File

@ -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