diff --git a/qiita_db/software.py b/qiita_db/software.py index 171490597..a21f8c4d0 100644 --- a/qiita_db/software.py +++ b/qiita_db/software.py @@ -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() diff --git a/qiita_db/test/test_software.py b/qiita_db/test/test_software.py index 022fd0889..59cb468fe 100644 --- a/qiita_db/test/test_software.py +++ b/qiita_db/test/test_software.py @@ -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) @@ -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) @@ -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)