Skip to content

delete-root-analysis-artifact #2244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix errors
  • Loading branch information
antgonza committed Aug 18, 2017
commit 3e1787620d22b39d1824a8efa36eb8206934e347
35 changes: 16 additions & 19 deletions qiita_db/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,25 +573,22 @@ def delete(cls, artifact_id):
WHERE artifact_id = %s"""
qdb.sql_connection.TRN.add(sql, [artifact_id])

# This block only applies if the artifact has a study AKA not an
# analysis
if study is not None:
# 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)

sql = """UPDATE qiita.prep_template
SET artifact_id = NULL
WHERE prep_template_id IN %s"""
qdb.sql_connection.TRN.add(
sql, [tuple(pt.id for pt in instance.prep_templates)])
else:
sql = """DELETE FROM qiita.parent_artifact
WHERE artifact_id = %s"""
qdb.sql_connection.TRN.add(sql, [artifact_id])
# 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
WHERE prep_template_id IN %s"""
qdb.sql_connection.TRN.add(
sql, [tuple(pt.id for pt in instance.prep_templates)])
else:
sql = """DELETE FROM qiita.parent_artifact
WHERE artifact_id = %s"""
qdb.sql_connection.TRN.add(sql, [artifact_id])

# Detach the artifact from the study_artifact table
sql = "DELETE FROM qiita.study_artifact WHERE artifact_id = %s"
Expand Down
3 changes: 3 additions & 0 deletions qiita_db/test/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down