Skip to content

Commit 330ff8a

Browse files
Merge pull request #3217 from antgonza/general-fixes
fix #3216 + other smaller fixes
2 parents d617907 + 508bdd0 commit 330ff8a

File tree

7 files changed

+37
-3
lines changed

7 files changed

+37
-3
lines changed

qiita_core/util.py

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def get_qiita_version():
9696
try:
9797
repo = Repo(git_repo_path)
9898
sha = repo.active_branch.commit.hexsha
99+
repo.__del__()
99100
except (InvalidGitRepositoryError, TypeError):
100101
sha = ''
101102

qiita_db/analysis.py

+16
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ class Analysis(qdb.base.QiitaObject):
6969
_portal_table = "analysis_portal"
7070
_analysis_id_column = 'analysis_id'
7171

72+
@classmethod
73+
def iter(cls):
74+
"""Iter over the analyses"""
75+
with qdb.sql_connection.TRN:
76+
sql = """SELECT DISTINCT analysis_id
77+
FROM qiita.analysis
78+
JOIN qiita.analysis_portal USING (analysis_id)
79+
JOIN qiita.portal_type USING (portal_type_id)
80+
WHERE portal = %s
81+
ORDER BY analysis_id"""
82+
qdb.sql_connection.TRN.add(sql, [qiita_config.portal])
83+
aids = qdb.sql_connection.TRN.execute_fetchflatten()
84+
85+
for aid in aids:
86+
yield cls(aid)
87+
7288
@classmethod
7389
def get_by_status(cls, status):
7490
"""Returns all Analyses with given status

qiita_db/metadata_template/base_metadata_template.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ def _helper_get_categories(table):
6363
WHERE sample_id = '{1}'""".format(table, QIITA_COLUMN_NAME)
6464
qdb.sql_connection.TRN.add(sql)
6565
results = qdb.sql_connection.TRN.execute_fetchflatten()
66-
if results:
66+
if results and results != [None]:
6767
results = sorted(loads(results[0]))
68+
else:
69+
results = []
6870
return results
6971

7072

qiita_db/sql_connection.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ def _raise_execution_error(self, sql, sql_args, error):
198198
ec_lu = errorcodes.lookup(error.pgcode)
199199
raise ValueError(
200200
"Error running SQL: %s. MSG: %s\n" % (ec_lu, str(error)))
201-
except (KeyError, AttributeError, TypeError):
201+
# the order of except statements is important, do not change
202+
except (KeyError, AttributeError, TypeError) as error:
203+
raise ValueError("Error running SQL query: %s" % str(error))
204+
except ValueError as error:
202205
raise ValueError("Error running SQL query: %s" % str(error))
203206

204207
@_checker

qiita_db/test/test_analysis.py

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
# -----------------------------------------------------------------------------
2323

2424

25+
class TestAnalysisIter(TestCase):
26+
def test_iter(self):
27+
obs = list(qdb.analysis.Analysis.iter())
28+
exp = [
29+
qdb.analysis.Analysis(1), qdb.analysis.Analysis(2),
30+
qdb.analysis.Analysis(3), qdb.analysis.Analysis(4),
31+
qdb.analysis.Analysis(5), qdb.analysis.Analysis(6)]
32+
self.assertCountEqual(obs, exp)
33+
34+
2535
@qiita_test_checker()
2636
class TestAnalysis(TestCase):
2737
def setUp(self):

qiita_pet/handlers/admin_processing_job.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
class AdminProcessingJobBaseClass(BaseHandler):
2121
def _check_access(self):
22-
if self.current_user.level not in {'admin', 'wet-lab admin'}:
22+
if self.current_user is None or self.current_user.level not in {
23+
'admin', 'wet-lab admin'}:
2324
raise HTTPError(403, reason="User %s doesn't have sufficient "
2425
"privileges to view error page" %
2526
self.current_user.email)

scripts/qiita-recover-jobs

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def _retrieve_queue_jobs():
5050

5151
# ignore the merge-jobs and get unique values
5252
qiita_jids = jobs.NAME.str.replace('merge-', '').unique()
53+
qiita_jids = [x.replace('.txt', '') for x in qiita_jids]
5354

5455
return set(qiita_jids)
5556

0 commit comments

Comments
 (0)