Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix transaction error
  • Loading branch information
antgonza committed Jun 8, 2022
commit a90530bc60bdbb0ef0ab48ebfc4bf1da3300329f
6 changes: 2 additions & 4 deletions qiita_db/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
TypeNode = namedtuple('TypeNode', ['id', 'job_id', 'name', 'type'])


IgnoreVisibilities = tuple([qdb.util.convert_to_id('archived', "visibility")])


class Artifact(qdb.base.QiitaObject):
r"""Any kind of file (or group of files) stored in the system and its
attributes
Expand Down Expand Up @@ -1393,7 +1390,8 @@ def youngest_artifact(self):
WHERE visibility_id NOT IN %s
ORDER BY generated_timestamp DESC
LIMIT 1"""
qdb.sql_connection.TRN.add(sql, [self.id, IgnoreVisibilities])
qdb.sql_connection.TRN.add(
sql, [self.id, qdb.util.artifact_visibilities_to_skip()])
a_id = qdb.sql_connection.TRN.execute_fetchindex()
# If the current artifact has no children, the previous call will
# return an empty list, so the youngest artifact in the lineage is
Expand Down
2 changes: 1 addition & 1 deletion qiita_db/metadata_template/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def status(self):
JOIN qiita.visibility USING (visibility_id)
WHERE prep_template_id = %s and visibility_id NOT IN %s"""
qdb.sql_connection.TRN.add(
sql, [self._id, qdb.artifact.IgnoreVisibilities])
sql, [self._id, qdb.util.artifact_visibilities_to_skip()])

return qdb.util.infer_status(
qdb.sql_connection.TRN.execute_fetchindex())
Expand Down
4 changes: 2 additions & 2 deletions qiita_db/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def status(self):
JOIN qiita.study_artifact USING (artifact_id)
WHERE study_id = %s and visibility_id NOT IN %s"""
qdb.sql_connection.TRN.add(
sql, [self._id, qdb.artifact.IgnoreVisibilities])
sql, [self._id, qdb.util.artifact_visibilities_to_skip()])
return qdb.util.infer_status(
qdb.sql_connection.TRN.execute_fetchindex())

Expand Down Expand Up @@ -1101,7 +1101,7 @@ def artifacts(self, dtype=None, artifact_type=None):
JOIN qiita.artifact_type USING (artifact_type_id)
WHERE study_id = %s{0} AND visibility_id NOT IN %s
ORDER BY artifact_id""".format(sql_where)
sql_args.append(qdb.artifact.IgnoreVisibilities)
sql_args.append(qdb.util.artifact_visibilities_to_skip())

qdb.sql_connection.TRN.add(sql, sql_args)
return [qdb.artifact.Artifact(aid)
Expand Down
8 changes: 6 additions & 2 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,8 +1775,8 @@ def get_artifacts_information(artifact_ids, only_biom=True):
ps = {}
algorithm_az = {'': ''}
PT = qdb.metadata_template.prep_template.PrepTemplate
qdb.sql_connection.TRN.add(
sql, [tuple(artifact_ids), qdb.artifact.IgnoreVisibilities])
qdb.sql_connection.TRN.add(sql, [
tuple(artifact_ids), qdb.util.artifact_visibilities_to_skip()])
for row in qdb.sql_connection.TRN.execute_fetchindex():
aid, name, cid, cname, gt, aparams, dt, pid, pcid, pname, \
pparams, filepaths, _, prep_template_id = row
Expand Down Expand Up @@ -1952,6 +1952,10 @@ def open_file(filepath_or, *args, **kwargs):
fh.close()


def artifact_visibilities_to_skip():
return tuple([qdb.util.convert_to_id('archived', "visibility")])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new function for one line of code seems a little excessive. However I appreciate the readability. Not sure I would suggest unfolding it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried adding as a global variable in the artifact.py and as a member of the Artifact object but turns out that this is not possible because the code will try to initialize those variables when the code is initiated (and there is no database) so it fails, for example.



def generate_analysis_list(analysis_ids, public_only=False):
"""Get general analysis information

Expand Down