Skip to content

Commit

Permalink
rm circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
antgonza committed Dec 10, 2024
1 parent db968c3 commit 5c7fba0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
16 changes: 16 additions & 0 deletions qiita_db/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,22 @@ def create(cls, owner, name, description, from_default=False,
job.submit()
return instance

@classmethod
def delete_analysis_artifacts(cls, _id):
"""Deletes the artifacts linked to an artifact and then the analysis
Parameters
----------
_id : int
The analysis id
"""
analysis = cls(_id)
aids = [a.id for a in analysis.artifacts if not a.parents]
aids.sort(reverse=True)
for aid in aids:
cls.delete(aid)
cls.delete(analysis.id)

@classmethod
def delete(cls, _id):
"""Deletes an analysis
Expand Down
10 changes: 6 additions & 4 deletions qiita_db/metadata_template/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from iteration_utilities import duplicates

from qiita_core.exceptions import IncompetentQiitaDeveloperError
from qiita_ware.private_plugin import _delete_analysis_artifacts
import qiita_db as qdb
from .constants import (PREP_TEMPLATE_COLUMNS, TARGET_GENE_DATA_TYPES,
PREP_TEMPLATE_COLUMNS_TARGET_GENE)
Expand Down Expand Up @@ -281,6 +280,7 @@ def delete(cls, id_):
qdb.sql_connection.TRN.add(sql, args)
archived_artifacts = set(
qdb.sql_connection.TRN.execute_fetchflatten())
ANALYSIS = qdb.analysis.Analysis
if archived_artifacts:
for aid in archived_artifacts:
# before we can delete the archived artifact, we need
Expand All @@ -294,9 +294,11 @@ def delete(cls, id_):
qdb.sql_connection.TRN.add(sql, [aid])
analyses = set(
qdb.sql_connection.TRN.execute_fetchflatten())
for _id in analyses:
_delete_analysis_artifacts(qdb.analysis.Analysis(_id))
qdb.artifact.Artifact.delete(aid)
if analyses:
for _id in analyses:
ANALYSIS.delete_analysis_artifacts(_id)
else:
ANALYSIS.delete(aid)

# Delete the prep template filepaths
sql = """DELETE FROM qiita.prep_template_filepath
Expand Down
7 changes: 3 additions & 4 deletions qiita_db/test/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from qiita_core.util import qiita_test_checker
from qiita_core.testing import wait_for_processing_job
import qiita_db as qdb
from qiita_ware.private_plugin import _delete_analysis_artifacts


class ArtifactTestsReadOnly(TestCase):
Expand Down Expand Up @@ -1559,9 +1558,9 @@ def test_archive(self):
qdb.sql_connection.perform_as_transaction(sql)
sql = "UPDATE qiita.artifact SET visibility_id = 1"
qdb.sql_connection.perform_as_transaction(sql)
_delete_analysis_artifacts(qdb.analysis.Analysis(1))
_delete_analysis_artifacts(qdb.analysis.Analysis(2))
_delete_analysis_artifacts(qdb.analysis.Analysis(3))
qdb.analysis.Analysis.delete_analysis_artifacts(1)
qdb.analysis.Analysis.delete_analysis_artifacts(2)
qdb.analysis.Analysis.delete_analysis_artifacts(3)
for aid in [3, 2, 1]:
A.delete(aid)

Expand Down
14 changes: 2 additions & 12 deletions qiita_ware/private_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,6 @@ def delete_sample_or_column(job):
job._set_status('success')


def _delete_analysis_artifacts(analysis):
aids = [a.id for a in analysis.artifacts if not a.parents]
aids.sort(reverse=True)
for aid in aids:
qdb.artifact.Artifact.delete(aid)
qdb.analysis.Analysis.delete(analysis.id)


def delete_study(job):
"""Deletes a full study
Expand All @@ -315,7 +307,7 @@ def delete_study(job):

# deleting analyses
for analysis in study.analyses():
_delete_analysis_artifacts(analysis)
qdb.analysis.Analysis.delete_analysis_artifacts(analysis)

for pt in study.prep_templates():
if pt.artifact is not None:
Expand Down Expand Up @@ -375,9 +367,7 @@ def delete_analysis(job):
"""
with qdb.sql_connection.TRN:
analysis_id = job.parameters.values['analysis_id']
analysis = qdb.analysis.Analysis(analysis_id)

_delete_analysis_artifacts(analysis)
qdb.analysis.Analysis.delete_analysis_artifacts(analysis_id)

r_client.delete('analysis_delete_%d' % analysis_id)

Expand Down

0 comments on commit 5c7fba0

Please sign in to comment.