diff --git a/qiita_db/artifact.py b/qiita_db/artifact.py index f9321f1f6..15aa20a7f 100644 --- a/qiita_db/artifact.py +++ b/qiita_db/artifact.py @@ -573,11 +573,12 @@ def delete(cls, artifact_id): WHERE artifact_id = %s""" qdb.sql_connection.TRN.add(sql, [artifact_id]) - # If the artifact doesn't have parents, we move the files to the - # uploads folder. We also need to nullify the column in the prep - # template table - if not instance.parents: - qdb.util.move_filepaths_to_upload_folder(study.id, filepaths) + # If the artifact doesn't have parents and study is not None (is an + # analysis), we move the files to the uploads folder. We also need + # to nullify the column in the prep template table + if not instance.parents and study is not None: + qdb.util.move_filepaths_to_upload_folder( + study.id, filepaths) sql = """UPDATE qiita.prep_template SET artifact_id = NULL diff --git a/qiita_db/test/test_artifact.py b/qiita_db/test/test_artifact.py index 6441f6baf..eb573eb1f 100644 --- a/qiita_db/test/test_artifact.py +++ b/qiita_db/test/test_artifact.py @@ -721,6 +721,9 @@ def test_create_root_analysis(self): self.assertIsNone(obs.study) self.assertEqual(obs.analysis, qdb.analysis.Analysis(1)) + # testing that it can be deleted + qdb.artifact.Artifact.delete(obs.id) + def test_create_processed(self): exp_params = qdb.software.Parameters.from_default_params( qdb.software.DefaultParameters(1), {'input_data': 1})