TM module DELETE API fixes 56/13956/1
authorMonosij Ghosh <mono.ghosh@samsung.com>
Mon, 23 Dec 2024 08:30:13 +0000 (14:00 +0530)
committerMonosij Ghosh <mono.ghosh@samsung.com>
Mon, 23 Dec 2024 08:30:13 +0000 (14:00 +0530)
relevant error returned when trainingjob_id is not valid

Change-Id: I17ec901b3ef6e84f69e27556d1049b00e6984e86
Signed-off-by: Monosij Ghosh <mono.ghosh@samsung.com>
trainingmgr/db/trainingjob_db.py
trainingmgr/service/training_job_service.py

index 7271de0..24f0f17 100644 (file)
@@ -97,11 +97,7 @@ def delete_trainingjob_by_id(id: int):
 
 def get_trainingjob(id: int=None):
     if id is not None:
-        try:
-            tj = TrainingJob.query.filter(TrainingJob.id==id).one()
-            return tj
-        except NoResultFound as err:
-            raise DBException(f"Failed to get trainingjob by id: {id} due to {str(err)}")
+        return TrainingJob.query.filter(TrainingJob.id==id).one()
     else:
         tjs = TrainingJob.query.all()
         return tjs
index 24187d2..b604438 100644 (file)
@@ -33,6 +33,7 @@ from trainingmgr.service.pipeline_service import terminate_training_service
 from trainingmgr.service.featuregroup_service import  get_featuregroup_by_name, get_featuregroup_from_inputDataType
 from trainingmgr.common.trainingmgr_config import TrainingMgrConfig
 from trainingmgr.constants import Steps, States
+from sqlalchemy.orm.exc import NoResultFound
 
 trainingJobSchema = TrainingJobSchema()
 trainingJobsSchema = TrainingJobSchema(many=True)
@@ -120,6 +121,8 @@ def delete_training_job(training_job_id : int):
             return True
         else:
             return False
+    except NoResultFound :
+        return False
     except Exception as err :
         raise DBException(f"delete_trainining_job failed with exception : {str(err)}")
 
@@ -282,4 +285,4 @@ def update_trainingPipeline(trainingjob):
         return trainingjob
     except Exception as err:
         LOGGER.error(f"error in updating the trainingPipeline due to {str(err)}")
-        raise TMException("failed to update the trainingPipeline")
\ No newline at end of file
+        raise TMException("failed to update the trainingPipeline")