Skip to content

Commit 3e17876

Browse files
committed
fix errors
1 parent 899268a commit 3e17876

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

qiita_db/artifact.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -573,25 +573,22 @@ def delete(cls, artifact_id):
573573
WHERE artifact_id = %s"""
574574
qdb.sql_connection.TRN.add(sql, [artifact_id])
575575

576-
# This block only applies if the artifact has a study AKA not an
577-
# analysis
578-
if study is not None:
579-
# If the artifact doesn't have parents, we move the files to
580-
# the uploads folder. We also need to nullify the column in
581-
# the prep template table
582-
if not instance.parents:
583-
qdb.util.move_filepaths_to_upload_folder(
584-
study.id, filepaths)
585-
586-
sql = """UPDATE qiita.prep_template
587-
SET artifact_id = NULL
588-
WHERE prep_template_id IN %s"""
589-
qdb.sql_connection.TRN.add(
590-
sql, [tuple(pt.id for pt in instance.prep_templates)])
591-
else:
592-
sql = """DELETE FROM qiita.parent_artifact
593-
WHERE artifact_id = %s"""
594-
qdb.sql_connection.TRN.add(sql, [artifact_id])
576+
# If the artifact doesn't have parents and study is not None (is an
577+
# analysis), we move the files to the uploads folder. We also need
578+
# to nullify the column in the prep template table
579+
if not instance.parents and study is not None:
580+
qdb.util.move_filepaths_to_upload_folder(
581+
study.id, filepaths)
582+
583+
sql = """UPDATE qiita.prep_template
584+
SET artifact_id = NULL
585+
WHERE prep_template_id IN %s"""
586+
qdb.sql_connection.TRN.add(
587+
sql, [tuple(pt.id for pt in instance.prep_templates)])
588+
else:
589+
sql = """DELETE FROM qiita.parent_artifact
590+
WHERE artifact_id = %s"""
591+
qdb.sql_connection.TRN.add(sql, [artifact_id])
595592

596593
# Detach the artifact from the study_artifact table
597594
sql = "DELETE FROM qiita.study_artifact WHERE artifact_id = %s"

qiita_db/test/test_artifact.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,9 @@ def test_create_root_analysis(self):
721721
self.assertIsNone(obs.study)
722722
self.assertEqual(obs.analysis, qdb.analysis.Analysis(1))
723723

724+
# testing that it can be deleted
725+
qdb.artifact.Artifact.delete(obs.id)
726+
724727
def test_create_processed(self):
725728
exp_params = qdb.software.Parameters.from_default_params(
726729
qdb.software.DefaultParameters(1), {'input_data': 1})

0 commit comments

Comments
 (0)