diff --git a/qiita_db/handlers/artifact.py b/qiita_db/handlers/artifact.py index 0ac6662c5..a34c7be1f 100644 --- a/qiita_db/handlers/artifact.py +++ b/qiita_db/handlers/artifact.py @@ -77,6 +77,7 @@ def get(self, artifact_id): 'processing_parameters': dict with the processing parameters used to generate the artifact or None 'files': dict with the artifact files, keyed by filepath type + 'parents': list of the parents artifact ids """ with qdb.sql_connection.TRN: artifact = _get_artifact(artifact_id) @@ -93,7 +94,8 @@ def get(self, artifact_id): artifact.can_be_submitted_to_vamps, 'prep_information': [p.id for p in artifact.prep_templates], 'study': study.id if study else None, - 'analysis': analysis.id if analysis else None} + 'analysis': analysis.id if analysis else None, + 'parents': [p.id for p in artifact.parents]} params = artifact.processing_parameters response['processing_parameters'] = ( params.values if params is not None else None) @@ -184,6 +186,8 @@ def post(self): analysis = self.get_argument('analysis', None) name = self.get_argument('name', None) dtype = self.get_argument('data_type', None) + parents = self.get_argument('parents', None) + job_id = self.get_argument('job_id', None) if prep_template is not None: prep_template = qdb.metadata_template.prep_template.PrepTemplate( @@ -191,9 +195,19 @@ def post(self): dtype = None if analysis is not None: analysis = qdb.analysis.Analysis(analysis) + if parents is not None: + # remember that this method is only accessed via the tests so + # to load an artifact with parents, the easiest it to use + # the job_id that is being used for testing and passed as a + # parameter + parents = [qdb.artifact.Artifact(p) for p in loads(parents)] + pp = qdb.processing_job.ProcessingJob(job_id).parameters + else: + pp = None a = qdb.artifact.Artifact.create( filepaths, artifact_type, name=name, prep_template=prep_template, + parents=parents, processing_parameters=pp, analysis=analysis, data_type=dtype) self.write({'artifact': a.id}) diff --git a/qiita_db/handlers/tests/test_artifact.py b/qiita_db/handlers/tests/test_artifact.py index d826a5e28..c42a9120d 100644 --- a/qiita_db/handlers/tests/test_artifact.py +++ b/qiita_db/handlers/tests/test_artifact.py @@ -86,6 +86,7 @@ def test_get_artifact(self): 'prep_information': [1], 'study': 1, 'analysis': None, + 'parents': [], 'processing_parameters': None, 'files': exp_fps} self.assertEqual(loads(obs.body), exp) @@ -109,6 +110,7 @@ def test_get_artifact(self): 'prep_information': [], 'study': None, 'analysis': 1, + 'parents': [8], 'processing_parameters': {'biom_table': '8', 'depth': '9000', 'subsample_multinomial': 'False'}, 'files': exp_fps}