From c5d338d1537e9b6b6f87b94f313c039d8447bff8 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Tue, 9 Dec 2025 15:29:02 -0700 Subject: [PATCH 1/2] untangle Analysis.create and build_analysis_files --- qiita_db/analysis.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/qiita_db/analysis.py b/qiita_db/analysis.py index 0ccd088c2..c585d82ef 100644 --- a/qiita_db/analysis.py +++ b/qiita_db/analysis.py @@ -147,7 +147,8 @@ def create( description : str Description of the analysis from_default : bool, optional - If True, use the default analysis to populate selected samples. + If True, use the default analysis to populate selected samples; + when True, we will create a `build_analysis_files` job. Default False. merge_duplicated_sample_ids : bool, optional If the duplicated sample ids in the selected studies should be @@ -155,13 +156,22 @@ def create( the artifact id categories : list of str, optional If not None, use _only_ these categories for the metaanalysis - reservation : str + reservation : str, optional The slurm reservation to asign to the analysis Returns ------- qdb.analysis.Analysis The newly created analysis + + Notes + ----- + Before 12.09.25 this method was fully tangled with `build_analysis_files`, which + meant that we couldn't create a stand alone analysis; additionally, this method + had the intrinsic assumption that we can create an analysis not from default but not + pass any sample/artifact information - which will create an empty analysis but still submit + a build_analysis_files file. Thus, we are using this assumption to define if we should + create the `build_analysis_files` job """ with qdb.sql_connection.TRN: portal_id = qdb.util.convert_to_id( @@ -199,6 +209,7 @@ def create( if reservation is not None: instance.slurm_reservation = reservation + if from_default: # Once the analysis is created, we can create the mapping file and # the initial set of artifacts plugin = qdb.software.Software.from_name_and_version("Qiita", "alpha") @@ -218,8 +229,8 @@ def create( qdb.sql_connection.TRN.add(sql, [a_id, job.id]) qdb.sql_connection.TRN.execute() - # Doing the submission outside of the transaction - job.submit() + job.submit() + return instance @classmethod From 3d6f6c3eceddd55c77156e82272e84b60e9ceef2 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Tue, 9 Dec 2025 15:47:11 -0700 Subject: [PATCH 2/2] add TRN --- qiita_db/analysis.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/qiita_db/analysis.py b/qiita_db/analysis.py index c585d82ef..44f37e365 100644 --- a/qiita_db/analysis.py +++ b/qiita_db/analysis.py @@ -222,12 +222,15 @@ def create( "categories": categories, }, ) + job = qdb.processing_job.ProcessingJob.create(owner, params, True) - sql = """INSERT INTO qiita.analysis_processing_job - (analysis_id, processing_job_id) - VALUES (%s, %s)""" - qdb.sql_connection.TRN.add(sql, [a_id, job.id]) - qdb.sql_connection.TRN.execute() + + with qdb.sql_connection.TRN: + sql = """INSERT INTO qiita.analysis_processing_job + (analysis_id, processing_job_id) + VALUES (%s, %s)""" + qdb.sql_connection.TRN.add(sql, [a_id, job.id]) + qdb.sql_connection.TRN.execute() job.submit()