Skip to content

fix #3022 #3030

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 2 commits into from
Sep 9, 2020
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
21 changes: 18 additions & 3 deletions qiita_db/software.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,26 @@ def active(self):
-------
bool
Whether the command is active or not

Notes
-----
This method differentiates between commands based on analysis_only. The
commands that are not for analysis (processing) will return as active
if they have the same name than a command that is active; this helps
for situations where the processing plugins are updated but some
commands didn't change its version.
"""
with qdb.sql_connection.TRN:
sql = """SELECT active
FROM qiita.software_command
WHERE command_id = %s"""
if self.analysis_only:
sql = """SELECT active
FROM qiita.software_command
WHERE command_id = %s"""
else:
sql = """SELECT EXISTS (
SELECT active FROM qiita.software_command
WHERE name IN (
SELECT name FROM qiita.software_command
WHERE command_id = %s) AND active = true)"""
qdb.sql_connection.TRN.add(sql, [self.id])
return qdb.sql_connection.TRN.execute_fetchlast()

Expand Down
24 changes: 24 additions & 0 deletions qiita_db/test/test_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ def test_create_error(self):
self.outputs)

def test_create(self):
# let's deactivate all current plugins and commands; this is not
# important to test the creation but it is important to test if a
# command is active as the new commands should take precedence and
# should make the old commands active if they have the same name
qdb.software.Software.deactivate_all()

# note that here we are adding commands to an existing software
obs = qdb.software.Command.create(
self.software, "Test Command", "This is a command for testing",
self.parameters, self.outputs)
Expand All @@ -355,6 +362,7 @@ def test_create(self):
{'parameters': [], 'outputs': [],
'ignore_parent_command': False})

# here we are creating a new software that we will add new commads to
obs = qdb.software.Command.create(
self.software, "Test Command 2", "This is a command for testing",
self.parameters, analysis_only=True)
Expand Down Expand Up @@ -426,6 +434,22 @@ def test_create(self):
'ignore_parent_command': False}
self.assertEqual(obs.merging_scheme, exp)

# now that we are done with the regular creation testing we can create
# a new command with the name of an old deprecated command and make
# sure that is not deprecated now
# 1. let's find the previous command and make sure is deprecated
cmd_name = 'Split libraries FASTQ'
old_cmd = [cmd for cmd in self.software.commands
if cmd.name == cmd_name][0]
self.assertFalse(old_cmd.active)

# 2. let's create a new command with the same name and check that now
# the old and the new are active
new_cmd = qdb.software.Command.create(
software, cmd_name, cmd_name, parameters, outputs=outputs)
self.assertTrue(old_cmd.active)
self.assertTrue(new_cmd.active)

def test_activate(self):
qdb.software.Software.deactivate_all()
tester = qdb.software.Command(1)
Expand Down