Skip to content

Commit f985552

Browse files
committed
Merge pull request #1166 from squirrelo/fix-1061
Fix 1061 - analysis.jobs always returns list
2 parents ea328af + 2c9af07 commit f985552

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

qiita_db/analysis.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,12 @@ def jobs(self):
425425
Returns
426426
-------
427427
list of ints
428-
Job ids for jobs in analysis
428+
Job ids for jobs in analysis. Empty list if no jobs attached.
429429
"""
430430
conn_handler = SQLConnectionHandler()
431431
sql = ("SELECT job_id FROM qiita.analysis_job WHERE "
432432
"analysis_id = %s".format(self._table))
433433
job_ids = conn_handler.execute_fetchall(sql, (self._id, ))
434-
if job_ids == []:
435-
return None
436434
return [job_id[0] for job_id in job_ids]
437435

438436
@property

qiita_db/test/test_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_retrieve_jobs(self):
304304
def test_retrieve_jobs_none(self):
305305
new = Analysis.create(User("admin@foo.bar"), "newAnalysis",
306306
"A New Analysis", Analysis(1))
307-
self.assertEqual(new.jobs, None)
307+
self.assertEqual(new.jobs, [])
308308

309309
def test_retrieve_pmid(self):
310310
self.assertEqual(self.analysis.pmid, "121112")

qiita_pet/handlers/analysis_handlers.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,14 @@ def get(self, analysis_id):
144144

145145
dropped_samples = analysis.dropped_samples
146146
dropped = defaultdict(list)
147-
if dropped_samples:
148-
for proc_data_id, samples in viewitems(dropped_samples):
149-
if not samples:
150-
continue
151-
proc_data = ProcessedData(proc_data_id)
152-
data_type = proc_data.data_type()
153-
study = proc_data.study
154-
dropped[data_type].append((Study(study).title, len(samples),
155-
', '.join(samples)))
147+
for proc_data_id, samples in viewitems(dropped_samples):
148+
if not samples:
149+
continue
150+
proc_data = ProcessedData(proc_data_id)
151+
data_type = proc_data.data_type()
152+
study = proc_data.study
153+
dropped[data_type].append((Study(study).title, len(samples),
154+
', '.join(samples)))
156155

157156
self.render("analysis_results.html",
158157
jobres=jobres, aname=analysis.name, dropped=dropped,

qiita_pet/templates/select_commands.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
{% autoescape None %}
33

44
{%block head%}
5+
56
<script>
7+
function check_selection(){
8+
if($('.command:checkbox:checked').length > 0){
9+
return true;
10+
}else {
11+
$('#error').text('Please select at least one command.');
12+
return false;
13+
}
14+
}
15+
616
$(function () {
717
$('#data-types-tabs a:first').tab('show')
818
})
@@ -12,8 +22,8 @@
1222
{%block content %}
1323

1424
<h1>Select Commands</h1>
15-
16-
<form role="form" action="/analysis/wait/{{aid}}" method="post">
25+
<span id="error" style="color:red"></span>
26+
<form role="form" action="/analysis/wait/{{aid}}" method="post" onsubmit="return check_selection()">
1727
<div style="padding-bottom:25px;">
1828
Rarefaction Depth: <input type="number" min="10" id="rarefaction-depth" name="rarefaction-depth" class="form-control" style="width:10em;">
1929
</div>
@@ -35,7 +45,7 @@ <h1>Select Commands</h1>
3545
{% for command in commands[data_type] %}
3646
<tr>
3747
<td style="width:20px;">
38-
<input id="{{data_type}}#{{command.name}}" type="checkbox" name="commands" value="{{data_type}}#{{command.name}}">
48+
<input id="{{data_type}}#{{command.name}}" type="checkbox" name="commands" class="command" value="{{data_type}}#{{command.name}}">
3949
</td>
4050
<td>
4151
<label style="font-weight:normal;" for="{{data_type}}#{{command.name}}">{{command.name}}</label>

qiita_ware/analysis_pipeline.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ def _build_analysis_files(analysis, r_depth=None, **kwargs):
2727
The analysis to build files for
2828
r_depth : int, optional
2929
Rarefaction depth for biom table creation. Default None
30+
31+
Raises
32+
------
33+
RuntimeError
34+
No jobs are attached to the given analysis
3035
"""
36+
if not analysis.jobs:
37+
raise RuntimeError("Analysis %d has no jobs attached!" % analysis.id)
38+
3139
# create the biom tables and add jobs to the analysis
3240
analysis.status = "running"
3341
analysis.build_files(r_depth)

0 commit comments

Comments
 (0)