Skip to content

fix #3216 + other smaller fixes #3217

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 3 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions qiita_core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def get_qiita_version():
try:
repo = Repo(git_repo_path)
sha = repo.active_branch.commit.hexsha
repo.__del__()
except (InvalidGitRepositoryError, TypeError):
sha = ''

Expand Down
16 changes: 16 additions & 0 deletions qiita_db/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ class Analysis(qdb.base.QiitaObject):
_portal_table = "analysis_portal"
_analysis_id_column = 'analysis_id'

@classmethod
def iter(cls):
"""Iter over the analyses"""
with qdb.sql_connection.TRN:
sql = """SELECT DISTINCT analysis_id
FROM qiita.analysis
JOIN qiita.analysis_portal USING (analysis_id)
JOIN qiita.portal_type USING (portal_type_id)
WHERE portal = %s
ORDER BY analysis_id"""
qdb.sql_connection.TRN.add(sql, [qiita_config.portal])
aids = qdb.sql_connection.TRN.execute_fetchflatten()

for aid in aids:
yield cls(aid)

@classmethod
def get_by_status(cls, status):
"""Returns all Analyses with given status
Expand Down
4 changes: 3 additions & 1 deletion qiita_db/metadata_template/base_metadata_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def _helper_get_categories(table):
WHERE sample_id = '{1}'""".format(table, QIITA_COLUMN_NAME)
qdb.sql_connection.TRN.add(sql)
results = qdb.sql_connection.TRN.execute_fetchflatten()
if results:
if results and results != [None]:
results = sorted(loads(results[0]))
else:
results = []
return results


Expand Down
5 changes: 4 additions & 1 deletion qiita_db/sql_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ def _raise_execution_error(self, sql, sql_args, error):
ec_lu = errorcodes.lookup(error.pgcode)
raise ValueError(
"Error running SQL: %s. MSG: %s\n" % (ec_lu, str(error)))
except (KeyError, AttributeError, TypeError):
# the order of except statements is important, do not change
except (KeyError, AttributeError, TypeError) as error:
raise ValueError("Error running SQL query: %s" % str(error))
except ValueError as error:
raise ValueError("Error running SQL query: %s" % str(error))

@_checker
Expand Down
10 changes: 10 additions & 0 deletions qiita_db/test/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
# -----------------------------------------------------------------------------


class TestAnalysisIter(TestCase):
def test_iter(self):
obs = list(qdb.analysis.Analysis.iter())
exp = [
qdb.analysis.Analysis(1), qdb.analysis.Analysis(2),
qdb.analysis.Analysis(3), qdb.analysis.Analysis(4),
qdb.analysis.Analysis(5), qdb.analysis.Analysis(6)]
self.assertCountEqual(obs, exp)


@qiita_test_checker()
class TestAnalysis(TestCase):
def setUp(self):
Expand Down
3 changes: 2 additions & 1 deletion qiita_pet/handlers/admin_processing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

class AdminProcessingJobBaseClass(BaseHandler):
def _check_access(self):
if self.current_user.level not in {'admin', 'wet-lab admin'}:
if self.current_user is None or self.current_user.level not in {
'admin', 'wet-lab admin'}:
raise HTTPError(403, reason="User %s doesn't have sufficient "
"privileges to view error page" %
self.current_user.email)
Expand Down
1 change: 1 addition & 0 deletions scripts/qiita-recover-jobs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _retrieve_queue_jobs():

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

return set(qiita_jids)

Expand Down