Skip to content

Commit c9045ff

Browse files
josenavasantgonza
authored andcommitted
Fix 2190 (#2292)
* Adding patch to add the 'name' parameter to all validate commands * Adding the parameter 'name' automatically and adding a test for it * Removing extra blank line * Adding dflt value to artifact name * Edited the wrong file * Adding user defined name at creation time * Fixing test
1 parent ae3dc0c commit c9045ff

File tree

7 files changed

+66
-17
lines changed

7 files changed

+66
-17
lines changed

qiita_db/processing_job.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ def release(self):
367367
parents = None
368368
params = None
369369
cmd_out_id = None
370+
name = None
370371
data_type = a_info['data_type']
371372
analysis = qdb.analysis.Analysis(
372373
job.parameters.values['analysis'])
@@ -376,6 +377,7 @@ def release(self):
376377
parents = job.input_artifacts
377378
params = job.parameters
378379
cmd_out_id = provenance['cmd_out_id']
380+
name = provenance['name']
379381
analysis = None
380382
data_type = None
381383

@@ -385,7 +387,7 @@ def release(self):
385387
a = qdb.artifact.Artifact.create(
386388
filepaths, atype, parents=parents,
387389
processing_parameters=params,
388-
analysis=analysis, data_type=data_type)
390+
analysis=analysis, data_type=data_type, name=name)
389391

390392
self._set_status('success')
391393

@@ -540,7 +542,7 @@ def _complete_artifact_definition(self, artifact_data):
540542

541543
qdb.artifact.Artifact.create(
542544
filepaths, atype, prep_template=pt, analysis=an,
543-
data_type=data_type)
545+
data_type=data_type, name=job_params['name'])
544546
self._set_status('success')
545547

546548
def _complete_artifact_transformation(self, artifacts_data):
@@ -612,7 +614,8 @@ def _complete_artifact_transformation(self, artifacts_data):
612614
cmd_out_id = qdb.util.convert_to_id(
613615
out_name, "command_output", "name")
614616
provenance = {'job': self.id,
615-
'cmd_out_id': cmd_out_id}
617+
'cmd_out_id': cmd_out_id,
618+
'name': out_name}
616619

617620
# Get the validator command for the current artifact type and
618621
# create a new job

qiita_db/software.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,17 @@ def create(cls, software, name, description, parameters, outputs=None,
361361
for atid in supported_types]
362362
qdb.sql_connection.TRN.add(sql, sql_params, many=True)
363363
# If this is the validate command, we need to add the
364-
# provenance parameter. This is used internally, that's why
365-
# we are adding it here
364+
# provenance and name parameters. These are used internally,
365+
# that's why we are adding them here
366366
if name == 'Validate':
367367
sql = """INSERT INTO qiita.command_parameter
368368
(command_id, parameter_name, parameter_type,
369369
required, default_value)
370-
VALUES (%s, 'provenance', 'string', 'False', NULL)
370+
VALUES (%s, 'name', 'string', 'False',
371+
'dflt_name'),
372+
(%s, 'provenance', 'string', 'False', NULL)
371373
"""
372-
qdb.sql_connection.TRN.add(sql, [c_id])
374+
qdb.sql_connection.TRN.add(sql, [c_id, c_id])
373375

374376
# Add the outputs to the command
375377
if outputs:

qiita_db/support_files/patches/59.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Sep 15, 2017
2+
-- Adding "name" parameter to validate commands
3+
4+
DO $do$
5+
DECLARE
6+
cmd RECORD;
7+
BEGIN
8+
FOR cmd IN
9+
SELECT command_id FROM qiita.software_command WHERE name = 'Validate'
10+
LOOP
11+
INSERT INTO qiita.command_parameter (command_id, parameter_name, parameter_type, required, default_value)
12+
VALUES (cmd.command_id, 'name', 'string', 'False', 'default_name');
13+
END LOOP;
14+
END $do$

qiita_db/test/test_artifact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ def test_delete_as_output_job(self):
10041004
'template': 1,
10051005
'provenance': dumps(
10061006
{'job': "bcc7ebcd-39c1-43e4-af2d-822e3589f14d",
1007-
'cmd_out_id': 3})}
1007+
'cmd_out_id': 3, 'name': 'test-delete'})}
10081008
)
10091009
)
10101010
parent = qdb.processing_job.ProcessingJob(

qiita_db/test/test_processing_job.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ def test_complete_multiple_outputs(self):
325325
'provenance': dumps(
326326
{'job': job.id,
327327
'cmd_out_id': qdb.util.convert_to_id(
328-
'out1', "command_output", "name")})})
328+
'out1', "command_output", "name"),
329+
'name': 'out1'})})
329330
user = qdb.user.User('test@foo.bar')
330331
obs1 = qdb.processing_job.ProcessingJob.create(user, params)
331332
obs1._set_status('running')
@@ -336,7 +337,8 @@ def test_complete_multiple_outputs(self):
336337
'provenance': dumps(
337338
{'job': job.id,
338339
'cmd_out_id': qdb.util.convert_to_id(
339-
'out1', "command_output", "name")})})
340+
'out1', "command_output", "name"),
341+
'name': 'out1'})})
340342
obs2 = qdb.processing_job.ProcessingJob.create(user, params)
341343
obs2._set_status('running')
342344
# Make sure that we link the original job with its validator jobs
@@ -635,7 +637,8 @@ def test_outputs(self):
635637
'artifact_type': 'BIOM',
636638
'provenance': dumps(
637639
{'job': job.id,
638-
'cmd_out_id': 3})}
640+
'cmd_out_id': 3,
641+
'name': 'outArtifact'})}
639642
)
640643
obs = qdb.processing_job.ProcessingJob.create(
641644
qdb.user.User('test@foo.bar'), params)
@@ -645,12 +648,11 @@ def test_outputs(self):
645648
job.release_validators()
646649
self.assertEqual(job.status, 'success')
647650

651+
artifact = qdb.artifact.Artifact(exp_artifact_count)
648652
obs = job.outputs
649-
self.assertEqual(
650-
obs, {'OTU table': qdb.artifact.Artifact(exp_artifact_count)})
651-
self._clean_up_files.extend(
652-
[afp for _, afp, _ in
653-
qdb.artifact.Artifact(exp_artifact_count).filepaths])
653+
self.assertEqual(obs, {'OTU table': artifact})
654+
self._clean_up_files.extend([afp for _, afp, _ in artifact.filepaths])
655+
self.assertEqual(artifact.name, 'outArtifact')
654656

655657
def test_processing_job_worflow(self):
656658
# testing None

qiita_db/test/test_software.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,33 @@ def test_create(self):
308308
self.assertEqual(obs.optional_parameters, exp_optional)
309309
self.assertTrue(obs.analysis_only)
310310

311+
# Test that the internal parameters in "Validate"
312+
# are created automatically
313+
software = qdb.software.Software.create(
314+
"New Type Software", "1.0.0",
315+
"This is adding a new software for testing", "env_name",
316+
"start_plugin", "artifact definition")
317+
parameters = {
318+
'template': ('prep_template', None),
319+
'analysis': ('analysis', None),
320+
'files': ('string', None),
321+
'artifact_type': ('string', None)}
322+
obs = qdb.software.Command.create(
323+
software, "Validate", "Test creating a validate command",
324+
parameters)
325+
self.assertEqual(obs.name, "Validate")
326+
self.assertEqual(obs.description, "Test creating a validate command")
327+
exp_required = {
328+
'template': ('prep_template', [None]),
329+
'analysis': ('analysis', [None]),
330+
'files': ('string', [None]),
331+
'artifact_type': ('string', [None])}
332+
self.assertEqual(obs.required_parameters, exp_required)
333+
exp_optional = {'name': ['string', 'dflt_name'],
334+
'provenance': ['string', None]}
335+
self.assertEqual(obs.optional_parameters, exp_optional)
336+
self.assertFalse(obs.analysis_only)
337+
311338
def test_activate(self):
312339
qdb.software.Software.deactivate_all()
313340
tester = qdb.software.Command(1)

qiita_pet/handlers/api_proxy/artifact.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ def artifact_post_req(user_id, filepaths, artifact_type, name,
217217
Parameters.load(command, values_dict={
218218
'template': prep_template_id,
219219
'files': dumps(cleaned_filepaths),
220-
'artifact_type': artifact_type
220+
'artifact_type': artifact_type,
221+
'name': name
221222
}))
222223

223224
# Submit the job

0 commit comments

Comments
 (0)