@@ -1217,16 +1217,16 @@ def release(self):
12171217
12181218 provenance = loads (self .parameters .values ["provenance" ])
12191219 job = ProcessingJob (provenance ["job" ])
1220+ pvals = job .parameters .values
12201221 if "data_type" in a_info :
12211222 # This job is resulting from a private job
12221223 parents = None
12231224 params = None
12241225 name = None
12251226 data_type = a_info ["data_type" ]
1226- pvals = job .parameters .values
12271227 if "analysis" in pvals :
12281228 cmd_out_id = None
1229- analysis = qdb .analysis .Analysis (job . parameters . values ["analysis" ])
1229+ analysis = qdb .analysis .Analysis (pvals ["analysis" ])
12301230 else :
12311231 cmd_out_id = provenance ["cmd_out_id" ]
12321232 analysis = None
@@ -1237,8 +1237,31 @@ def release(self):
12371237 params = job .parameters
12381238 cmd_out_id = provenance ["cmd_out_id" ]
12391239 name = provenance ["name" ]
1240- analysis = None
12411240 data_type = None
1241+ if "analysis" in pvals :
1242+ analysis = qdb .analysis .Analysis (pvals ["analysis" ])
1243+ if "artifacts" in pvals :
1244+ # as this is going to be the first artifact of an analysis, we
1245+ # need to provide the data type so we are going to make sure all
1246+ # the parents data_types are the same and assigning that one; note
1247+ # that (1) we are doing this to be stringent but it should be responsability
1248+ # of the plugin creating this artifact, and (2) to keep the same functionality
1249+ # we are going to make sure that params is not set as it shouldn't be passed when
1250+ # assiging to an analysis
1251+ params = None
1252+ data_type = set (
1253+ [
1254+ qdb .artifact .Artifact (aid ).data_type
1255+ for aid in pvals ["artifacts" ]
1256+ ]
1257+ )
1258+ if len (data_type ) != 1 :
1259+ raise ValueError (
1260+ f"Not valid parents data_types: { data_type } "
1261+ )
1262+ data_type = data_type .pop ()
1263+ else :
1264+ analysis = None
12421265
12431266 # Create the artifact
12441267 atype = a_info ["artifact_type" ]
@@ -1470,6 +1493,7 @@ def _complete_artifact_transformation(self, artifacts_data):
14701493 validator_jobs = []
14711494 with qdb .sql_connection .TRN :
14721495 cmd_id = self .command .id
1496+ parameters = self .parameters .values
14731497 for out_name , a_data in artifacts_data .items ():
14741498 # Correct the format of the filepaths parameter so we can
14751499 # create a validate job
@@ -1506,6 +1530,12 @@ def _complete_artifact_transformation(self, artifacts_data):
15061530 # belong to the same analysis, so we can just ask the
15071531 # first artifact for the analysis that it belongs to
15081532 analysis = self .input_artifacts [0 ].analysis .id
1533+ elif "analysis" in parameters :
1534+ # if we made it this far in the if/elif block it means that
1535+ # we are dealing with a job that was generated to link study/template
1536+ # artifacts and an analysis; thus, using the analysis parameter from
1537+ # the job itself
1538+ analysis = parameters ["analysis" ]
15091539
15101540 # Once the validate job completes, it needs to know if it has
15111541 # been generated from a command (and how) or if it has been
@@ -1521,11 +1551,10 @@ def _complete_artifact_transformation(self, artifacts_data):
15211551 cmd_out_id = qdb .sql_connection .TRN .execute_fetchlast ()
15221552 naming_params = self .command .naming_order
15231553 if naming_params :
1524- params = self .parameters .values
15251554 art_name = "%s %s" % (
15261555 out_name ,
15271556 " " .join (
1528- [str (params [p ]).split ("/" )[- 1 ] for p in naming_params ]
1557+ [str (parameters [p ]).split ("/" )[- 1 ] for p in naming_params ]
15291558 ),
15301559 )
15311560 else :
0 commit comments