Skip to content

Commit d982171

Browse files
committed
data_type
1 parent 6a89495 commit d982171

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

qiita_db/artifact.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ def create(
329329
qiita_db.artifact.Artifact
330330
A new instance of Artifact
331331
332+
Raises
333+
------
334+
QiitaDBArtifactCreationError
335+
If `filepaths` is not provided
336+
If both `parents` and `prep_template` are provided
337+
If none of `parents` and `prep_template` are provided
338+
If `parents` is provided but `processing_parameters` is not
339+
If both `prep_template` and `processing_parameters` is provided
340+
If not all the artifacts in `parents` belong to the same study
341+
332342
Notes
333343
-----
334344
The visibility of the artifact is set by default to `sandbox` if
@@ -344,29 +354,29 @@ def create(
344354
)
345355

346356
# Check that the combination of parameters is correct
347-
if bool(parents) and bool(prep_template):
348-
raise qdb.exceptions.QiitaDBArtifactCreationError(
349-
"Not valid: parents and prep_template provided"
350-
)
351-
elif bool(parents) and not bool(processing_parameters):
357+
counts = (
358+
int(bool(parents or processing_parameters))
359+
+ int(prep_template is not None)
360+
+ int(bool(analysis or data_type))
361+
)
362+
if counts != 1:
363+
# More than one parameter has been provided
352364
raise qdb.exceptions.QiitaDBArtifactCreationError(
353-
"Not valid: both parents and processing_parameters need to be provided"
365+
"One and only one of parents, prep template or analysis must "
366+
"be provided"
354367
)
355-
elif bool(prep_template) and bool(processing_parameters):
368+
elif bool(parents) != bool(processing_parameters):
369+
# When provided, parents and processing parameters both should be
370+
# provided (this is effectively doing an XOR)
356371
raise qdb.exceptions.QiitaDBArtifactCreationError(
357-
"Not valid: both prep_template and processing_parameters provided"
372+
"When provided, both parents and processing parameters should "
373+
"be provided"
358374
)
359375
elif bool(analysis) and not bool(data_type):
376+
# When provided, analysis and data_type both should be
377+
# provided (this is effectively doing an XOR)
360378
raise qdb.exceptions.QiitaDBArtifactCreationError(
361-
"Not valid: both analysis and data_type need to be provided"
362-
)
363-
elif bool(prep_template) and bool(data_type):
364-
raise qdb.exceptions.QiitaDBArtifactCreationError(
365-
"Not valid: both prep_template and data_type need to be provided"
366-
)
367-
elif not bool(prep_template) and not bool(parents) and not bool(analysis):
368-
raise qdb.exceptions.QiitaDBArtifactCreationError(
369-
"Not valid: no prep_template, parents or analysis provided"
379+
"When provided, both analysis and data_type should be provided"
370380
)
371381

372382
# There are three different ways of creating an Artifact, but all of

qiita_db/processing_job.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,15 @@ def release(self):
12441244
parents = [
12451245
qdb.artifact.Artifact(aid) for aid in pvals["artifacts"]
12461246
]
1247+
# as this is going to be the first artifact of an analysis, we
1248+
# need to provide the data type so we are going to make sure all
1249+
# the parents data_types are the same and assing that one
1250+
data_type = set([p.data_type for p in parents])
1251+
if len(data_type) != 1:
1252+
raise ValueError(
1253+
f"Not valida parents data_types: {data_type}"
1254+
)
1255+
data_type = data_type.pop()
12471256
else:
12481257
analysis = None
12491258

0 commit comments

Comments
 (0)