Skip to content

Commit 899268a

Browse files
committed
delete-root-analysis-artifact
1 parent 6b59f37 commit 899268a

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

qiita_db/artifact.py

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

576-
# If the artifact doesn't have parents, we move the files to the
577-
# uploads folder. We also need to nullify the column in the prep
578-
# template table
579-
if not instance.parents:
580-
qdb.util.move_filepaths_to_upload_folder(study.id, filepaths)
581-
582-
sql = """UPDATE qiita.prep_template
583-
SET artifact_id = NULL
584-
WHERE prep_template_id IN %s"""
585-
qdb.sql_connection.TRN.add(
586-
sql, [tuple(pt.id for pt in instance.prep_templates)])
587-
else:
588-
sql = """DELETE FROM qiita.parent_artifact
589-
WHERE artifact_id = %s"""
590-
qdb.sql_connection.TRN.add(sql, [artifact_id])
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])
591595

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

0 commit comments

Comments
 (0)