From b2454dcafe511cf96985ab3d03f65e4b99547797 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Sun, 17 Oct 2021 10:28:15 +0200 Subject: [PATCH] Use TagHandlerSession in ModelPersistenceContext Eliminates an unnecessary flush --- lib/galaxy/job_execution/output_collect.py | 11 +++++++---- lib/galaxy/model/store/discover.py | 6 ------ test/unit/jobs/test_job_context.py | 1 + 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/job_execution/output_collect.py b/lib/galaxy/job_execution/output_collect.py index 0e67ca67ca0..2204d487979 100644 --- a/lib/galaxy/job_execution/output_collect.py +++ b/lib/galaxy/job_execution/output_collect.py @@ -207,6 +207,13 @@ class JobContext(ModelPersistenceContext, BaseJobContext): self.object_store = object_store self.final_job_state = final_job_state self.flush_per_n_datasets = flush_per_n_datasets + self._tag_handler = None + + @property + def tag_handler(self): + if self._tag_handler is None: + self._tag_handler = self.app.tag_handler.create_tag_handler_session() + return self._tag_handler @property def work_context(self): @@ -221,10 +228,6 @@ class JobContext(ModelPersistenceContext, BaseJobContext): user = None return user - @property - def tag_handler(self): - return self.app.tag_handler - def persist_object(self, obj): self.sa_session.add(obj) diff --git a/lib/galaxy/model/store/discover.py b/lib/galaxy/model/store/discover.py index 9f1ec661030..82539fd09e5 100644 --- a/lib/galaxy/model/store/discover.py +++ b/lib/galaxy/model/store/discover.py @@ -129,13 +129,7 @@ class ModelPersistenceContext(metaclass=abc.ABCMeta): if created_from_basename is not None: primary_data.created_from_basename = created_from_basename - has_flushed = False if tag_list: - # If we have a tag we need a primary id, so need to flush here - # TODO: eliminate creating tag associations within create dataset - # We can do this incrementally by not passing in a tag list. - self.flush() - has_flushed = True self.tag_handler.add_tags_from_list(self.job.user, primary_data, tag_list) # Move data from temp location to dataset location diff --git a/test/unit/jobs/test_job_context.py b/test/unit/jobs/test_job_context.py index 6bbacc62331..019ab2e87df 100644 --- a/test/unit/jobs/test_job_context.py +++ b/test/unit/jobs/test_job_context.py @@ -55,6 +55,7 @@ def test_job_context_discover_outputs_flushes_once(mocker): job = model.Job() job.history = h sa_session.add(job) + sa_session.flush() job_working_directory = tempfile.mkdtemp() setup_data(job_working_directory) permission_provider = PermissionProvider()