def create_new_study_id(self, study_name=None): # type: (Optional[str]) -> int session = self.scoped_session() if study_name is None: study_name = self._create_unique_study_name(session) study = models.StudyModel(study_name=study_name, direction=structs.StudyDirection.NOT_SET) session.add(study) if not self._commit_with_integrity_check(session): raise ValueError( "study_name {} already exists. Please use a different name.". format(study_name)) self.logger.info('A new study created with name: {}'.format( study.study_name)) return study.study_id
def create_new_study_id(self, study_name=None): # type: (Optional[str]) -> int session = self.scoped_session() if study_name is None: study_name = self._create_unique_study_name(session) study = models.StudyModel(study_name=study_name, direction=structs.StudyDirection.NOT_SET) session.add(study) if not self._commit_with_integrity_check(session): raise structs.DuplicatedStudyError( "Another study with name '{}' already exists. " "Please specify a different name, or reuse the existing one " "by setting `load_if_exists` (for Python API) or " "`--skip-if-exists` flag (for CLI).".format(study_name)) self.logger.info('A new study created with name: {}'.format(study.study_name)) return study.study_id