Skip to content

Commit d41102b

Browse files
authored
fix #3022 (#3030)
* fix #3022 * adding tests
1 parent 6d30da1 commit d41102b

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

qiita_db/software.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,26 @@ def active(self):
622622
-------
623623
bool
624624
Whether the command is active or not
625+
626+
Notes
627+
-----
628+
This method differentiates between commands based on analysis_only. The
629+
commands that are not for analysis (processing) will return as active
630+
if they have the same name than a command that is active; this helps
631+
for situations where the processing plugins are updated but some
632+
commands didn't change its version.
625633
"""
626634
with qdb.sql_connection.TRN:
627-
sql = """SELECT active
628-
FROM qiita.software_command
629-
WHERE command_id = %s"""
635+
if self.analysis_only:
636+
sql = """SELECT active
637+
FROM qiita.software_command
638+
WHERE command_id = %s"""
639+
else:
640+
sql = """SELECT EXISTS (
641+
SELECT active FROM qiita.software_command
642+
WHERE name IN (
643+
SELECT name FROM qiita.software_command
644+
WHERE command_id = %s) AND active = true)"""
630645
qdb.sql_connection.TRN.add(sql, [self.id])
631646
return qdb.sql_connection.TRN.execute_fetchlast()
632647

qiita_db/test/test_software.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ def test_create_error(self):
330330
self.outputs)
331331

332332
def test_create(self):
333+
# let's deactivate all current plugins and commands; this is not
334+
# important to test the creation but it is important to test if a
335+
# command is active as the new commands should take precedence and
336+
# should make the old commands active if they have the same name
337+
qdb.software.Software.deactivate_all()
338+
339+
# note that here we are adding commands to an existing software
333340
obs = qdb.software.Command.create(
334341
self.software, "Test Command", "This is a command for testing",
335342
self.parameters, self.outputs)
@@ -351,6 +358,7 @@ def test_create(self):
351358
{'parameters': [], 'outputs': [],
352359
'ignore_parent_command': False})
353360

361+
# here we are creating a new software that we will add new commads to
354362
obs = qdb.software.Command.create(
355363
self.software, "Test Command 2", "This is a command for testing",
356364
self.parameters, analysis_only=True)
@@ -422,6 +430,22 @@ def test_create(self):
422430
'ignore_parent_command': False}
423431
self.assertEqual(obs.merging_scheme, exp)
424432

433+
# now that we are done with the regular creation testing we can create
434+
# a new command with the name of an old deprecated command and make
435+
# sure that is not deprecated now
436+
# 1. let's find the previous command and make sure is deprecated
437+
cmd_name = 'Split libraries FASTQ'
438+
old_cmd = [cmd for cmd in self.software.commands
439+
if cmd.name == cmd_name][0]
440+
self.assertFalse(old_cmd.active)
441+
442+
# 2. let's create a new command with the same name and check that now
443+
# the old and the new are active
444+
new_cmd = qdb.software.Command.create(
445+
software, cmd_name, cmd_name, parameters, outputs=outputs)
446+
self.assertTrue(old_cmd.active)
447+
self.assertTrue(new_cmd.active)
448+
425449
def test_activate(self):
426450
qdb.software.Software.deactivate_all()
427451
tester = qdb.software.Command(1)

0 commit comments

Comments
 (0)