@@ -573,21 +573,25 @@ def delete(cls, artifact_id):
573
573
WHERE artifact_id = %s"""
574
574
qdb .sql_connection .TRN .add (sql , [artifact_id ])
575
575
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 ])
591
595
592
596
# Detach the artifact from the study_artifact table
593
597
sql = "DELETE FROM qiita.study_artifact WHERE artifact_id = %s"
0 commit comments