Skip to content

Commit

Permalink
fix #3122 (#3136)
Browse files Browse the repository at this point in the history
* fix #3122

* fix #3122

* fix #3124
  • Loading branch information
antgonza committed Aug 24, 2021
1 parent faf74df commit 3c24801
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def test_generate_analysis_list(self):
obs = qdb.util.generate_analysis_list([1, 2, 3, 5])
exp = [{'mapping_files': [
(16, qdb.util.get_filepath_information(16)['fullpath'])],
'description': 'A test analysis', 'artifacts': [9], 'name':
'description': 'A test analysis', 'artifacts': [8, 9], 'name':
'SomeAnalysis', 'analysis_id': 1, 'visibility': 'private'},
{'mapping_files': [], 'description': 'Another test analysis',
'artifacts': [], 'name': 'SomeSecondAnalysis',
Expand Down
3 changes: 1 addition & 2 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1942,8 +1942,7 @@ def generate_analysis_list(analysis_ids, public_only=False):

sql = """
SELECT analysis_id, a.name, a.description, a.timestamp,
array_agg(DISTINCT CASE WHEN command_id IS NOT NULL
THEN artifact_id END),
array_agg(DISTINCT artifact_id),
array_agg(DISTINCT visibility),
array_agg(DISTINCT CASE WHEN filepath_type = 'plain_text'
THEN filepath_id END)
Expand Down
9 changes: 5 additions & 4 deletions qiita_ware/private_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ def delete_study(job):
_delete_analysis_artifacts(analysis)

for pt in study.prep_templates():
to_delete = list(pt.artifact.descendants.nodes())
to_delete.reverse()
for td in to_delete:
qdb.artifact.Artifact.delete(td.id)
if pt.artifact:
to_delete = list(pt.artifact.descendants.nodes())
to_delete.reverse()
for td in to_delete:
qdb.artifact.Artifact.delete(td.id)
MT.prep_template.PrepTemplate.delete(pt.id)

if MT.sample_template.SampleTemplate.exists(study_id):
Expand Down
20 changes: 20 additions & 0 deletions qiita_ware/test/test_private_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,26 @@ def test_delete_study_empty_study(self):
"lab_person_id": StudyPerson(1)}
new_study = Study.create(User('test@foo.bar'),
"Fried Chicken Microbiome %s" % time(), info)
# creating a sample information file
metadata = pd.DataFrame.from_dict({
'Sample1': {'physical_specimen_location': 'location1',
'taxon_id': '9606',
'scientific_name': 'homo sapiens'},
'Sample2': {'physical_specimen_location': 'location1',
'taxon_id': '9606',
'scientific_name': 'homo sapiens'},
'Sample3': {'physical_specimen_location': 'location1',
'taxon_id': '9606',
'scientific_name': 'homo sapiens'}}, orient='index')
SampleTemplate.create(metadata, new_study)
# creating a preparation information file
metadata = pd.DataFrame.from_dict(
{'Sample1': {'center_name': 'ANL',
'target_subfragment': 'V4',
'center_project_name': 'Test Project'}},
orient='index', dtype=str)
PrepTemplate.create(metadata, new_study, '16S')

job = self._create_job('delete_study', {'study': new_study.id})
private_task(job.id)
self.assertEqual(job.status, 'success')
Expand Down

0 comments on commit 3c24801

Please sign in to comment.