Skip to content

Commit 4c1e91f

Browse files
committed
MAINT: be defensive on artifact prep assocation expectations
1 parent 26a9f75 commit 4c1e91f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

qiita_db/artifact.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,8 +1463,22 @@ def prep_templates(self):
14631463
FROM qiita.preparation_artifact
14641464
WHERE artifact_id = %s"""
14651465
qdb.sql_connection.TRN.add(sql, [self.id])
1466-
return [qdb.metadata_template.prep_template.PrepTemplate(pt_id)
1467-
for pt_id in qdb.sql_connection.TRN.execute_fetchflatten()]
1466+
templates = [qdb.metadata_template.prep_template.PrepTemplate(pt_id)
1467+
for pt_id in qdb.sql_connection.TRN.execute_fetchflatten()]
1468+
1469+
if len(templates) > 1:
1470+
# We never expect an artifact to be associated with multiple
1471+
# preparations
1472+
ids = [p.id for p in templates]
1473+
msg = f"Artifact({self.id}) associated with preps: {sorted(ids)}"
1474+
raise ValueError(msg)
1475+
1476+
if len(templates) == 0:
1477+
# An artifact must be associated with a template
1478+
msg = f"Artifact({self.id}) is not associated with a template"
1479+
raise ValueError(msg)
1480+
1481+
return templates
14681482

14691483
@property
14701484
def study(self):

0 commit comments

Comments
 (0)