From f0de72b690ae9850e6e03f8c51df8d7c853cc597 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 11:44:21 -0500 Subject: [PATCH 01/39] Remove transaction helper from test.unit.job_execution --- test/unit/job_execution/test_job_io.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/unit/job_execution/test_job_io.py b/test/unit/job_execution/test_job_io.py index 749b972c5879..92dfca514f49 100644 --- a/test/unit/job_execution/test_job_io.py +++ b/test/unit/job_execution/test_job_io.py @@ -9,7 +9,6 @@ from galaxy.files.plugins import FileSourcePluginsConfig from galaxy.job_execution.setup import JobIO from galaxy.model import Job -from galaxy.model.base import transaction from galaxy.model.unittest_utils import GalaxyDataTestApp WORKING_DIRECTORY = "/tmp" @@ -42,10 +41,9 @@ def app() -> FileSourcesMockApp: @pytest.fixture def job(app: FileSourcesMockApp) -> Job: job = Job() - app.model.session.add(job) session = app.model.session - with transaction(session): - session.commit() + session.add(job) + session.commit() return job From f39702b8f52a4c0b80728f45ed12cacfb5e284ee Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 11:45:51 -0500 Subject: [PATCH 02/39] Remove transaction helper from test.unit.workflows --- test/unit/workflows/test_run_parameters.py | 14 +++++--------- test/unit/workflows/test_workflow_progress.py | 6 ++---- test/unit/workflows/workflow_support.py | 4 +--- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/test/unit/workflows/test_run_parameters.py b/test/unit/workflows/test_run_parameters.py index 5718ac923a40..f66cea2b9d57 100644 --- a/test/unit/workflows/test_run_parameters.py +++ b/test/unit/workflows/test_run_parameters.py @@ -1,5 +1,4 @@ from galaxy import model -from galaxy.model.base import transaction from galaxy.model.unittest_utils.utils import random_email from galaxy.workflow.run_request import ( _normalize_inputs, @@ -102,9 +101,8 @@ def add_step(**kwds): setattr(workflow_step, key, value) workflow.steps.append(workflow_step) - trans.app.model.context.add( - workflow, - ) + session = trans.app.model.context + session.add(workflow) add_step(type="data_input", order_index=0, tool_inputs={"name": "input1"}) add_step(type="data_input", order_index=1, tool_inputs={"name": "input2"}) @@ -118,11 +116,9 @@ def add_step(**kwds): tool_id="cat1", order_index=4, ) - session = trans.app.model.context - with transaction(session): - session.commit() + session.commit() # Expunge and reload to ensure step state is as expected from database. workflow_id = workflow.id - trans.app.model.context.expunge_all() + session.expunge_all() - return trans.app.model.session.get(model.Workflow, workflow_id) + return session.get(model.Workflow, workflow_id) diff --git a/test/unit/workflows/test_workflow_progress.py b/test/unit/workflows/test_workflow_progress.py index d0d2f9902e79..785aad5d53f2 100644 --- a/test/unit/workflows/test_workflow_progress.py +++ b/test/unit/workflows/test_workflow_progress.py @@ -1,7 +1,6 @@ from typing import cast from galaxy import model -from galaxy.model.base import transaction from galaxy.util.unittest import TestCase from galaxy.workflow.run import ( ModuleInjector, @@ -196,10 +195,9 @@ def test_subworkflow_progress(self): subworkflow_invocation = self.invocation.create_subworkflow_invocation_for_step( self.invocation.workflow.step_by_index(1) ) - self.app.model.session.add(subworkflow_invocation) session = self.app.model.session - with transaction(session): - session.commit() + session.add(subworkflow_invocation) + session.commit() progress = self._new_workflow_progress() remaining_steps = progress.remaining_steps() (subworkflow_step, subworkflow_invocation_step) = remaining_steps[0] diff --git a/test/unit/workflows/workflow_support.py b/test/unit/workflows/workflow_support.py index a3b8374637df..c5579b92d9d5 100644 --- a/test/unit/workflows/workflow_support.py +++ b/test/unit/workflows/workflow_support.py @@ -5,7 +5,6 @@ from galaxy import model from galaxy.app_unittest_utils import galaxy_mock from galaxy.managers.workflows import WorkflowsManager -from galaxy.model.base import transaction from galaxy.util.bunch import Bunch from galaxy.workflow.modules import module_factory @@ -23,8 +22,7 @@ def save_workflow(self, workflow): workflow.stored_workflow = stored_workflow stored_workflow.user = self.user self.sa_session.add(stored_workflow) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return stored_workflow @property From 6f47682a39c64727e85575e396f6d07dab8ba1be Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 13:11:54 -0500 Subject: [PATCH 03/39] Remove transaction helper from test.unit.data --- test/unit/data/model/conftest.py | 18 +-------- test/unit/data/model/test_model_discovery.py | 4 +- test/unit/data/model/test_model_store.py | 4 +- .../unit/data/test_dataset_materialization.py | 7 +--- test/unit/data/test_galaxy_mapping.py | 5 +-- test/unit/data/test_metadata_limit.py | 4 +- test/unit/data/test_model_copy.py | 37 +++++++------------ test/unit/data/test_mutable_json_column.py | 13 +++---- 8 files changed, 27 insertions(+), 65 deletions(-) diff --git a/test/unit/data/model/conftest.py b/test/unit/data/model/conftest.py index a10f10cb00ce..9dbb352e51a0 100644 --- a/test/unit/data/model/conftest.py +++ b/test/unit/data/model/conftest.py @@ -1,4 +1,3 @@ -import contextlib import os import tempfile import uuid @@ -508,19 +507,6 @@ def f(**kwd): return f -# utility functions - - -@contextlib.contextmanager -def transaction(session): - if not session.in_transaction(): - with session.begin(): - yield - else: - yield - - def write_to_db(session, model) -> None: - with transaction(session): - session.add(model) - session.commit() + session.add(model) + session.commit() diff --git a/test/unit/data/model/test_model_discovery.py b/test/unit/data/model/test_model_discovery.py index 7237d37f0ef0..affe5d188752 100644 --- a/test/unit/data/model/test_model_discovery.py +++ b/test/unit/data/model/test_model_discovery.py @@ -5,7 +5,6 @@ from galaxy import model from galaxy.model import store -from galaxy.model.base import transaction from galaxy.model.store.discover import persist_target_to_export_store from galaxy.model.unittest_utils import GalaxyDataTestApp @@ -245,8 +244,7 @@ def _import_directory_to_history(app, target, work_directory): sa_session = app.model.context sa_session.add_all([u, import_history]) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() assert len(import_history.datasets) == 0 diff --git a/test/unit/data/model/test_model_store.py b/test/unit/data/model/test_model_store.py index aa13b658dfa6..d693bb2385c3 100644 --- a/test/unit/data/model/test_model_store.py +++ b/test/unit/data/model/test_model_store.py @@ -22,7 +22,6 @@ from galaxy import model from galaxy.model import store -from galaxy.model.base import transaction from galaxy.model.metadata import MetadataTempFile from galaxy.model.orm.now import now from galaxy.model.unittest_utils import GalaxyDataTestApp @@ -1161,8 +1160,7 @@ def add_and_commit(self, *objs): def commit(self): session = self.model.session - with transaction(session): - session.commit() + session.commit() def write_primary_file(self, dataset_instance, contents): primary = NamedTemporaryFile("w") diff --git a/test/unit/data/test_dataset_materialization.py b/test/unit/data/test_dataset_materialization.py index 3573da8d3cab..3c016b2b0e76 100644 --- a/test/unit/data/test_dataset_materialization.py +++ b/test/unit/data/test_dataset_materialization.py @@ -10,7 +10,6 @@ LibraryDatasetDatasetAssociation, store, ) -from galaxy.model.base import transaction from galaxy.model.deferred import ( materialize_collection_instance, materializer_factory, @@ -34,8 +33,7 @@ def test_undeferred_hdas_untouched(tmpdir): hda_fh = tmpdir.join("file.txt") hda_fh.write("Moo Cow") hda = _create_hda(sa_session, app.object_store, history, hda_fh, include_metadata_file=False) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() materializer = materializer_factory(True, object_store=app.object_store) assert materializer.ensure_materialized(hda) == hda @@ -365,8 +363,7 @@ def _test_hdca( ) sa_session.add(hdca) sa_session.add(collection) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() return hdca diff --git a/test/unit/data/test_galaxy_mapping.py b/test/unit/data/test_galaxy_mapping.py index 2e71b5d97b8c..67313f5e1ecf 100644 --- a/test/unit/data/test_galaxy_mapping.py +++ b/test/unit/data/test_galaxy_mapping.py @@ -14,7 +14,6 @@ import galaxy.model import galaxy.model.mapping as mapping from galaxy import model -from galaxy.model.base import transaction from galaxy.model.database_utils import create_database from galaxy.model.metadata import MetadataTempFile from galaxy.model.orm.util import ( @@ -234,9 +233,7 @@ def get_latest_entry(entries): self.new_hda(h2, name="2") session = self.session() - - with transaction(session): - session.commit() + session.commit() # _next_hid modifies history, plus trigger on HDA means 2 additional audit rows per history h1_audits = get_audit_table_entries(h1) diff --git a/test/unit/data/test_metadata_limit.py b/test/unit/data/test_metadata_limit.py index 27dc925cea46..380512bf74e3 100644 --- a/test/unit/data/test_metadata_limit.py +++ b/test/unit/data/test_metadata_limit.py @@ -7,7 +7,6 @@ HistoryDatasetAssociation, set_datatypes_registry, ) -from galaxy.model.base import transaction METADATA_LIMIT = 500 @@ -31,8 +30,7 @@ def create_bed_data(sa_session, string_size): sa_session.add(hda) hda.metadata.column_names = [big_string] assert hda.metadata.column_names - with transaction(sa_session): - sa_session.commit() + sa_session.commit() return hda diff --git a/test/unit/data/test_model_copy.py b/test/unit/data/test_model_copy.py index 4b827a972089..ab795174675f 100644 --- a/test/unit/data/test_model_copy.py +++ b/test/unit/data/test_model_copy.py @@ -14,7 +14,6 @@ setup_global_object_store_for_models, User, ) -from galaxy.model.base import transaction from galaxy.model.metadata import MetadataTempFile from galaxy.objectstore.unittest_utils import ( Config as TestConfig, @@ -40,8 +39,7 @@ def test_history_dataset_copy(num_datasets=NUM_DATASETS, include_metadata_file=I _create_hda(model, object_store, old_history, hda_path, include_metadata_file=include_metadata_file) session = model.context - with transaction(session): - session.commit() + session.commit() history_copy_timer = ExecutionTimer() original_update_time = old_history.update_time @@ -49,8 +47,7 @@ def test_history_dataset_copy(num_datasets=NUM_DATASETS, include_metadata_file=I new_history = old_history.copy(name="new name", target_user=old_history.user, all_datasets=True) session.add(new_history) session.add(old_history) - with transaction(session): - session.commit() + session.commit() session.refresh(old_history) new_update_time = session.get(model.History, old_history.id).update_time assert original_update_time == new_update_time @@ -76,6 +73,7 @@ def test_history_collection_copy(list_size=NUM_DATASETS): ) hdas.append(hda) + session = model.context list_elements = [] list_collection = model.DatasetCollection(collection_type="list:paired") for j in range(list_size): @@ -86,29 +84,24 @@ def test_history_collection_copy(list_size=NUM_DATASETS): collection=list_collection, element=paired_collection ) list_elements.append(paired_collection_element) - model.context.add_all([forward_dce, reverse_dce, paired_collection_element]) + session.add_all([forward_dce, reverse_dce, paired_collection_element]) history_dataset_collection = model.HistoryDatasetCollectionAssociation(collection=list_collection) history_dataset_collection.user = old_history.user - model.context.add(history_dataset_collection) - - session = model.context - with transaction(session): - session.commit() + session.add(history_dataset_collection) + session.commit() old_history.add_dataset_collection(history_dataset_collection) history_dataset_collection.add_item_annotation( - model.context, + session, old_history.user, history_dataset_collection, f"annotation #{history_dataset_collection.hid}", ) - session = model.context - with transaction(session): - session.commit() + session.commit() annotation_str = history_dataset_collection.get_item_annotation_str( - model.context, old_history.user, history_dataset_collection + session, old_history.user, history_dataset_collection ) # Saving magic SA invocations for detecting full flushes that may harm performance. @@ -126,12 +119,12 @@ def test_history_collection_copy(list_size=NUM_DATASETS): for hda in new_history.active_datasets: assert hda.get_size() == 3 - annotation_str = hda.get_item_annotation_str(model.context, old_history.user, hda) + annotation_str = hda.get_item_annotation_str(session, old_history.user, hda) assert annotation_str == f"annotation #{hda.hid}", annotation_str assert len(new_history.active_dataset_collections) == NUM_COLLECTIONS for hdca in new_history.active_dataset_collections: - annotation_str = hdca.get_item_annotation_str(model.context, old_history.user, hdca) + annotation_str = hdca.get_item_annotation_str(session, old_history.user, hdca) assert annotation_str == f"annotation #{hdca.hid}", annotation_str @@ -150,10 +143,9 @@ def _setup_mapping_and_user(): u = User(email="historycopy@example.com", password="password") h1 = History(name="HistoryCopyHistory1", user=u) - model.context.add_all([u, h1]) session = model.context - with transaction(session): - session.commit() + session.add_all([u, h1]) + session.commit() yield test_config, object_store, model, h1 @@ -172,8 +164,7 @@ def _create_hda( hda = HistoryDatasetAssociation(extension="bam", create_dataset=True, sa_session=sa_session) hda.visible = visible sa_session.add(hda) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() object_store.update_from_file(hda, file_name=path, create=True) if include_metadata_file: hda.metadata.from_JSON_dict(json_dict={"bam_index": MetadataTempFile.from_JSON({"kwds": {}, "filename": path})}) diff --git a/test/unit/data/test_mutable_json_column.py b/test/unit/data/test_mutable_json_column.py index 9bc67fbc68e0..6deece5ee402 100644 --- a/test/unit/data/test_mutable_json_column.py +++ b/test/unit/data/test_mutable_json_column.py @@ -1,7 +1,6 @@ import copy from galaxy import model -from galaxy.model.base import transaction from .test_galaxy_mapping import BaseModelTestCase @@ -9,17 +8,15 @@ class TestMutableColumn(BaseModelTestCase): def persist_and_reload(self, item): item_id = item.id session = self.model.session - with transaction(session): - session.commit() - self.model.session.expunge_all() - return self.model.session.get(model.DynamicTool, item_id) + session.commit() + session.expunge_all() + return session.get(model.DynamicTool, item_id) def test_metadata_mutable_column(self): w = model.DynamicTool() - self.model.session.add(w) session = self.model.session - with transaction(session): - session.commit() + session.add(w) + session.commit() w.value = {"x": "z"} # type:ignore[assignment] persisted = self.persist_and_reload(w) assert persisted.value == {"x": "z"} From a26cd0f35907cc22ca98d00cb8aea6e72395e41a Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 13:15:57 -0500 Subject: [PATCH 04/39] Remove transaction helper from test.unit.app.jobs --- test/unit/app/jobs/test_job_context.py | 7 ++----- test/unit/app/jobs/test_rule_helper.py | 4 +--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/test/unit/app/jobs/test_job_context.py b/test/unit/app/jobs/test_job_context.py index 29b030982595..f3119318b3f0 100644 --- a/test/unit/app/jobs/test_job_context.py +++ b/test/unit/app/jobs/test_job_context.py @@ -6,7 +6,6 @@ dataset_collector, JobContext, ) -from galaxy.model.base import transaction from galaxy.model.dataset_collections import builder from galaxy.tool_util.parser.output_collection_def import FilePatternDatasetCollectionDescription from galaxy.tool_util.provided_metadata import NullToolProvidedMetadata @@ -54,8 +53,7 @@ def test_job_context_discover_outputs_flushes_once(mocker): job = model.Job() job.history = h sa_session.add(job) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() job_working_directory = tempfile.mkdtemp() setup_data(job_working_directory) permission_provider = PermissionProvider() @@ -94,7 +92,6 @@ def test_job_context_discover_outputs_flushes_once(mocker): ) collection_builder.populate() assert spy.call_count == 0 - with transaction(sa_session): - sa_session.commit() + sa_session.commit() assert len(collection.dataset_instances) == 10 assert collection.dataset_instances[0].dataset.file_size == 1 diff --git a/test/unit/app/jobs/test_rule_helper.py b/test/unit/app/jobs/test_rule_helper.py index f3be1cdd20c0..81f1aeb94526 100644 --- a/test/unit/app/jobs/test_rule_helper.py +++ b/test/unit/app/jobs/test_rule_helper.py @@ -3,7 +3,6 @@ from galaxy import model from galaxy.jobs.rule_helper import RuleHelper from galaxy.model import mapping -from galaxy.model.base import transaction from galaxy.util import bunch USER_EMAIL_1 = "u1@example.com" @@ -199,5 +198,4 @@ def add(self, *args): for arg in args: self.model.context.add(arg) session = self.model.context - with transaction(session): - session.commit() + session.commit() From 1ce27e3fcb73b05903aa342546d952c30ff0bd01 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 13:24:22 -0500 Subject: [PATCH 05/39] Remove transaction helper from test.unit.app.managers --- .../managers/test_HistoryContentsManager.py | 21 ++++--------- test/unit/app/managers/test_HistoryManager.py | 30 +++++++------------ .../managers/test_JobConnectionsManager.py | 7 ++--- test/unit/app/managers/test_landing.py | 7 ++--- 4 files changed, 20 insertions(+), 45 deletions(-) diff --git a/test/unit/app/managers/test_HistoryContentsManager.py b/test/unit/app/managers/test_HistoryContentsManager.py index df260460a451..0f48f03c6f80 100644 --- a/test/unit/app/managers/test_HistoryContentsManager.py +++ b/test/unit/app/managers/test_HistoryContentsManager.py @@ -18,7 +18,6 @@ history_contents, ) from galaxy.managers.histories import HistoryManager -from galaxy.model.base import transaction from .base import ( BaseTestCase, CreatesCollectionsMixin, @@ -123,8 +122,7 @@ def test_orm_filtering(self): contents[6].deleted = True deleted = [contents[1], contents[4], contents[6]] session = self.app.model.context - with transaction(session): - session.commit() + session.commit() # TODO: cross db compat? filters = [parse_filter("deleted", "eq", "True")] @@ -143,9 +141,7 @@ def test_orm_filtering(self): contents[5].visible = False contents[6].visible = False invisible = [contents[2], contents[5], contents[6]] - session = self.app.model.context - with transaction(session): - session.commit() + session.commit() filters = [parse_filter("visible", "eq", "False")] assert self.contents_manager.contents(history, filters=filters) == invisible @@ -233,8 +229,7 @@ def get_create_time(item): # change the oldest created to update the update_time contents[0].name = "zany and/or wacky" session = self.app.model.context - with transaction(session): - session.commit() + session.commit() results = self.contents_manager.contents(history, order_by=desc("update_time")) assert contents[0] == results[0] @@ -252,8 +247,7 @@ def test_update_time_filter(self): # change the update_time by updating the name contents[3].name = "big ball of mud" session = self.app.model.context - with transaction(session): - session.commit() + session.commit() update_time = contents[3].update_time def get_update_time(item): @@ -283,15 +277,12 @@ def test_filtered_counting(self): self.hda_manager.delete(contents[4]) contents[6].deleted = True session = self.app.model.context - with transaction(session): - session.commit() + session.commit() contents[2].visible = False contents[5].visible = False contents[6].visible = False - session = self.app.model.context - with transaction(session): - session.commit() + session.commit() HDA = self.hda_manager.model_class assert self.contents_manager.contents_count(history, filters=[parsed_filter("orm", HDA.deleted == true())]) == 3 diff --git a/test/unit/app/managers/test_HistoryManager.py b/test/unit/app/managers/test_HistoryManager.py index 8696c7ba7c69..eb0b1224ffd0 100644 --- a/test/unit/app/managers/test_HistoryManager.py +++ b/test/unit/app/managers/test_HistoryManager.py @@ -24,7 +24,6 @@ HistoryManager, HistorySerializer, ) -from galaxy.model.base import transaction from .base import BaseTestCase default_password = "123456" @@ -504,10 +503,9 @@ def test_history_resume(self): job = model.Job() job.state = model.Job.states.PAUSED jobs = [job] - self.trans.sa_session.add(jobs[0]) session = self.trans.sa_session - with transaction(session): - session.commit() + session.add(jobs[0]) + session.commit() assert job.state == model.Job.states.PAUSED mock_paused_jobs.return_value = jobs history.resume_paused_jobs() @@ -853,8 +851,7 @@ def test_fn_filter_parsing(self): history3.add_item_annotation(self.trans.sa_session, user2, history3, "All work and no play") session = self.trans.sa_session - with transaction(session): - session.commit() + session.commit() assert anno_filter(history3) assert not anno_filter(history2) @@ -865,9 +862,7 @@ def test_fn_filter_parsing(self): self.history_manager.update(history3, dict(importable=True)) self.history_manager.update(history2, dict(importable=True)) history1.add_item_annotation(self.trans.sa_session, user2, history1, "All work and no play") - session = self.trans.sa_session - with transaction(session): - session.commit() + session.commit() shining_examples = self.history_manager.list( filters=self.filter_parser.parse_filters( @@ -920,18 +915,13 @@ def test_list(self): self.history_manager.delete(history3) test_annotation = "testing" - history2.add_item_annotation(self.trans.sa_session, user2, history2, test_annotation) - session = self.trans.sa_session - with transaction(session): - session.commit() - history3.add_item_annotation(self.trans.sa_session, user2, history3, test_annotation) - session = self.trans.sa_session - with transaction(session): - session.commit() - history3.add_item_annotation(self.trans.sa_session, user2, history4, test_annotation) session = self.trans.sa_session - with transaction(session): - session.commit() + history2.add_item_annotation(session, user2, history2, test_annotation) + session.commit() + history3.add_item_annotation(session, user2, history3, test_annotation) + session.commit() + history3.add_item_annotation(session, user2, history4, test_annotation) + session.commit() all_histories = [history1, history2, history3, history4] deleted_and_annotated = [history2, history3] diff --git a/test/unit/app/managers/test_JobConnectionsManager.py b/test/unit/app/managers/test_JobConnectionsManager.py index 5ec06f388fd7..a3e12d91d89b 100644 --- a/test/unit/app/managers/test_JobConnectionsManager.py +++ b/test/unit/app/managers/test_JobConnectionsManager.py @@ -7,7 +7,6 @@ HistoryDatasetCollectionAssociation, Job, ) -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.model.unittest_utils import GalaxyDataTestApp @@ -39,8 +38,7 @@ def setup_connected_dataset(sa_session: galaxy_scoped_session): output_job.add_output_dataset("output_hda", output_hda) output_job.add_output_dataset_collection("output_hdca", output_hdca) sa_session.add_all([center_hda, input_hda, input_hdca, output_hdca, input_job, output_job]) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() expected_graph = { "inputs": [ {"src": "HistoryDatasetAssociation", "id": input_hda.id}, @@ -71,8 +69,7 @@ def setup_connected_dataset_collection(sa_session: galaxy_scoped_session): output_job.add_output_dataset("output_hda", output_hda) output_job.add_output_dataset_collection("output_hdca", output_hdca) sa_session.add_all([center_hdca, input_hda1, input_hda2, input_hdca, output_hdca, input_job, output_job]) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() expected_graph = { "inputs": [ {"src": "HistoryDatasetAssociation", "id": input_hda1.id}, diff --git a/test/unit/app/managers/test_landing.py b/test/unit/app/managers/test_landing.py index f2ccb059b4bf..770ebb434a38 100644 --- a/test/unit/app/managers/test_landing.py +++ b/test/unit/app/managers/test_landing.py @@ -13,7 +13,6 @@ StoredWorkflow, Workflow, ) -from galaxy.model.base import transaction from galaxy.schema.schema import ( ClaimLandingPayload, CreateToolLandingRequestPayload, @@ -154,8 +153,7 @@ def _stored_workflow_request(self) -> CreateWorkflowLandingRequestPayload: stored_workflow = StoredWorkflow() stored_workflow.user = self.trans.user sa_session.add(stored_workflow) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() return CreateWorkflowLandingRequestPayload( workflow_id=self.app.security.encode_id(stored_workflow.id), @@ -173,8 +171,7 @@ def _workflow_request(self) -> CreateWorkflowLandingRequestPayload: workflow.stored_workflow = stored_workflow sa_session.add(stored_workflow) sa_session.add(workflow) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() return CreateWorkflowLandingRequestPayload( workflow_id=self.app.security.encode_id(workflow.id), From dee88049f57f3b52179d6119eb99c0da806f4bc5 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 13:42:20 -0500 Subject: [PATCH 06/39] Remove transaction helper from test.unit.app.tools Note: app.model.context.current == app.model.context. The `current` attr may have been a very legacy attribute still silently supported. --- test/unit/app/tools/conftest.py | 11 +--- test/unit/app/tools/test_actions.py | 7 +-- .../tools/test_collect_primary_datasets.py | 8 +-- test/unit/app/tools/test_column_parameters.py | 6 +- test/unit/app/tools/test_data_parameters.py | 11 ++-- test/unit/app/tools/test_error_reporting.py | 4 +- test/unit/app/tools/test_execution.py | 8 +-- test/unit/app/tools/test_history_imp_exp.py | 60 +++++++------------ test/unit/app/tools/test_metadata.py | 18 ++---- test/unit/app/tools/test_select_parameters.py | 6 +- .../tools/test_tool_shed_repository_cache.py | 6 +- test/unit/app/tools/test_toolbox.py | 8 +-- 12 files changed, 51 insertions(+), 102 deletions(-) diff --git a/test/unit/app/tools/conftest.py b/test/unit/app/tools/conftest.py index f69d6ea70bff..4a63e74d85cf 100644 --- a/test/unit/app/tools/conftest.py +++ b/test/unit/app/tools/conftest.py @@ -4,7 +4,6 @@ import pytest from galaxy.model import tool_shed_install -from galaxy.model.base import transaction from galaxy.model.tool_shed_install import mapping from galaxy.tool_shed.cache import ToolShedRepositoryCache from galaxy.tool_util.toolbox.base import ToolConfRepository @@ -25,12 +24,9 @@ def tool_shed_repository_cache(mock_app): @pytest.fixture def repos(mock_app): - repositories = [ - create_repo(mock_app.install_model.context, changeset=i + 1, installed_changeset=i) for i in range(10) - ] session = mock_app.install_model.context - with transaction(session): - session.commit() + repositories = [create_repo(session, changeset=i + 1, installed_changeset=i) for i in range(10)] + session.commit() return repositories @@ -72,8 +68,7 @@ def create_repo(session, changeset, installed_changeset, config_filename=None): repository.deleted = False repository.uninstalled = False session.add(repository) - with transaction(session): - session.commit() + session.commit() tool_dependency = tool_shed_install.ToolDependency( name="Name", version="100", diff --git a/test/unit/app/tools/test_actions.py b/test/unit/app/tools/test_actions.py index a6126cfb8b32..5d9fa582f7bf 100644 --- a/test/unit/app/tools/test_actions.py +++ b/test/unit/app/tools/test_actions.py @@ -7,7 +7,6 @@ from galaxy import model from galaxy.app_unittest_utils import tools_support from galaxy.exceptions import UserActivationRequiredException -from galaxy.model.base import transaction from galaxy.objectstore import BaseObjectStore from galaxy.tool_util.parser.output_objects import ToolOutput from galaxy.tool_util.parser.xml import parse_change_format @@ -71,8 +70,7 @@ def setUp(self): self.trans = MockTrans(self.app, self.history) self.app.model.context.add(history) session = self.app.model.context - with transaction(session): - session.commit() + session.commit() self.action = DefaultToolAction() self.app.config.len_file_path = "moocow" self.app.object_store = cast(BaseObjectStore, MockObjectStore()) @@ -130,8 +128,7 @@ def __add_dataset(self, state="ok"): hda.dataset.external_filename = "/tmp/datasets/dataset_001.dat" self.history.add_dataset(hda) session = self.app.model.context - with transaction(session): - session.commit() + session.commit() return hda def _simple_execute(self, contents=None, incoming=None): diff --git a/test/unit/app/tools/test_collect_primary_datasets.py b/test/unit/app/tools/test_collect_primary_datasets.py index fb612853b4db..93f0b2865868 100644 --- a/test/unit/app/tools/test_collect_primary_datasets.py +++ b/test/unit/app/tools/test_collect_primary_datasets.py @@ -7,7 +7,6 @@ util, ) from galaxy.app_unittest_utils import tools_support -from galaxy.model.base import transaction from galaxy.objectstore import BaseObjectStore from galaxy.tool_util.parser import output_collection_def from galaxy.tool_util.provided_metadata import ( @@ -446,12 +445,11 @@ def _setup_test_output(self): def _new_history(self, hdas=None, flush=True): hdas = hdas or [] history = model.History() - self.app.model.context.add(history) + session = self.app.model.context + session.add(history) for hda in hdas: history.add_dataset(hda, set_hid=False) - session = self.app.model.context - with transaction(session): - session.commit() + session.commit() return history diff --git a/test/unit/app/tools/test_column_parameters.py b/test/unit/app/tools/test_column_parameters.py index 11ac5f0317b6..b01e6d1ef45b 100644 --- a/test/unit/app/tools/test_column_parameters.py +++ b/test/unit/app/tools/test_column_parameters.py @@ -4,7 +4,6 @@ from galaxy import model from galaxy.app_unittest_utils.tools_support import datatypes_registry -from galaxy.model.base import transaction from galaxy.util import bunch from .util import BaseParameterTestCase @@ -61,10 +60,9 @@ def test_get_initial_value_override_newstyle_strips_c(self): def setUp(self): super().setUp() self.test_history = model.History() - self.app.model.context.add(self.test_history) session = self.app.model.context - with transaction(session): - session.commit() + session.add(self.test_history) + session.commit() self.trans = bunch.Bunch( app=self.app, get_history=lambda: self.test_history, diff --git a/test/unit/app/tools/test_data_parameters.py b/test/unit/app/tools/test_data_parameters.py index 4718f23dfa78..ea7a7352d92e 100644 --- a/test/unit/app/tools/test_data_parameters.py +++ b/test/unit/app/tools/test_data_parameters.py @@ -6,7 +6,6 @@ from galaxy import model from galaxy.app_unittest_utils import galaxy_mock -from galaxy.model.base import transaction from .util import BaseParameterTestCase @@ -147,19 +146,17 @@ def _new_hda(self): hda = model.HistoryDatasetAssociation() hda.visible = True hda.dataset = model.Dataset() - self.app.model.context.add(hda) session = self.app.model.context - with transaction(session): - session.commit() + session.add(hda) + session.commit() return hda def setUp(self): super().setUp() self.test_history = model.History() - self.app.model.context.add(self.test_history) session = self.app.model.context - with transaction(session): - session.commit() + session.add(self.test_history) + session.commit() self.trans = galaxy_mock.MockTrans(history=self.test_history) self.multiple = False self.optional = False diff --git a/test/unit/app/tools/test_error_reporting.py b/test/unit/app/tools/test_error_reporting.py index 7db9cb4bf60e..f0cde9c1fc8a 100644 --- a/test/unit/app/tools/test_error_reporting.py +++ b/test/unit/app/tools/test_error_reporting.py @@ -5,7 +5,6 @@ from galaxy import model from galaxy.app_unittest_utils.tools_support import UsesApp -from galaxy.model.base import transaction from galaxy.tools.errors import EmailErrorReporter from galaxy.util.unittest import TestCase @@ -141,5 +140,4 @@ def _setup_model_objects(self): def _commit_objects(self, objects): session = self.app.model.context session.add_all(objects) - with transaction(session): - session.commit() + session.commit() diff --git a/test/unit/app/tools/test_execution.py b/test/unit/app/tools/test_execution.py index 7e34757ec55d..ffb7c76e7ff9 100644 --- a/test/unit/app/tools/test_execution.py +++ b/test/unit/app/tools/test_execution.py @@ -10,7 +10,6 @@ import galaxy.model from galaxy.app_unittest_utils import tools_support from galaxy.managers.collections import DatasetCollectionManager -from galaxy.model.base import transaction from galaxy.model.orm.util import add_object_to_object_session from galaxy.util.bunch import Bunch from galaxy.util.unittest import TestCase @@ -131,12 +130,11 @@ def __add_dataset(self, id, state="ok"): hda.dataset = galaxy.model.Dataset() hda.dataset.state = "ok" - self.trans.sa_session.add(hda) + session = self.trans.sa_session + session.add(hda) add_object_to_object_session(self.history, hda) self.history.datasets.append(hda) - session = self.trans.sa_session - with transaction(session): - session.commit() + session.commit() return hda def __add_collection_dataset(self, id, collection_type="paired", *hdas): diff --git a/test/unit/app/tools/test_history_imp_exp.py b/test/unit/app/tools/test_history_imp_exp.py index 1f54029642da..402d2eb45d80 100644 --- a/test/unit/app/tools/test_history_imp_exp.py +++ b/test/unit/app/tools/test_history_imp_exp.py @@ -10,7 +10,6 @@ from galaxy import model from galaxy.app_unittest_utils.galaxy_mock import MockApp from galaxy.exceptions import MalformedContents -from galaxy.model.base import transaction from galaxy.model.orm.util import add_object_to_object_session from galaxy.objectstore.unittest_utils import Config as TestConfig from galaxy.tools.imp_exp import ( @@ -39,10 +38,9 @@ def _run_jihaw_cleanup(archive_dir, app=None): job.user = model.User(email="test@test.org", password="test") job.tool_stderr = "" jiha = model.JobImportHistoryArchive(job=job, archive_dir=archive_dir) - app.model.context.current.add_all([job, jiha]) session = app.model.context - with transaction(session): - session.commit() + session.add_all([job, jiha]) + session.commit() jihaw = JobImportHistoryArchiveWrapper(app, job.id) # yeehaw! return app, jihaw.cleanup_after_job() @@ -142,8 +140,7 @@ def test_export_dataset(): sa_session.add(d2) sa_session.add(h) sa_session.add(j) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() app.object_store.update_from_file(d1, file_name=t_data_path("1.txt"), create=True) app.object_store.update_from_file(d2, file_name=t_data_path("2.bed"), create=True) @@ -209,8 +206,7 @@ def test_export_dataset_with_deleted_and_purged(): sa_session.add(j1) sa_session.add(j2) sa_session.add(h) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() assert d1.deleted @@ -248,8 +244,7 @@ def test_multi_inputs(): sa_session.add(d3) sa_session.add(h) sa_session.add(j) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() app.object_store.update_from_file(d1, file_name=t_data_path("1.txt"), create=True) app.object_store.update_from_file(d2, file_name=t_data_path("2.bed"), create=True) @@ -319,8 +314,7 @@ def test_export_collection_history(): sa_session.add(hc1) sa_session.add(hc2) sa_session.add(j) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() imported_history = _import_export(app, h) @@ -390,8 +384,7 @@ def test_export_collection_with_mapping_history(): sa_session.add(hc2) sa_session.add(j1) sa_session.add(j2) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() implicit_collection_jobs = model.ImplicitCollectionJobs() j1.add_output_dataset_collection("out_file1", hc2) # really? @@ -411,8 +404,7 @@ def test_export_collection_with_mapping_history(): sa_session.add(implicit_collection_jobs) sa_session.add(ija1) sa_session.add(ija2) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() imported_history = _import_export(app, h) assert len(imported_history.jobs) == 2 @@ -441,8 +433,7 @@ def test_export_collection_with_datasets_from_other_history(): sa_session.add(d1) sa_session.add(d2) sa_session.add(hc1) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() imported_history = _import_export(app, h) @@ -466,8 +457,7 @@ def test_export_collection_with_copied_datasets_and_overlapping_hids(): sa_session.add(d1) sa_session.add(d2) sa_session.add(dataset_history) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() app.object_store.update_from_file(d1, file_name=t_data_path("1.txt"), create=True) app.object_store.update_from_file(d2, file_name=t_data_path("2.bed"), create=True) @@ -489,8 +479,7 @@ def test_export_collection_with_copied_datasets_and_overlapping_hids(): sa_session.add(d1_copy) sa_session.add(d2_copy) sa_session.add(hc1) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() _import_export(app, h) # Currently d1 and d1_copy would have conflicting paths in the tar file... this test verifies at least @@ -511,16 +500,14 @@ def test_export_copied_collection(): dce2 = model.DatasetCollectionElement(collection=c1, element=d2, element_identifier="reverse", element_index=1) sa_session.add_all((dce1, dce2, d1, d2, hc1)) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() hc2 = hc1.copy(element_destination=h) h.add_pending_items() assert h.hid_counter == 7 sa_session.add(hc2) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() assert hc2.copied_from_history_dataset_collection_association == hc1 @@ -549,8 +536,7 @@ def test_export_copied_objects_copied_outside_history(): dce2 = model.DatasetCollectionElement(collection=c1, element=d2, element_identifier="reverse", element_index=1) sa_session.add_all((dce1, dce2, d1, d2, hc1)) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() hc2 = hc1.copy(element_destination=h) @@ -558,8 +544,7 @@ def test_export_copied_objects_copied_outside_history(): other_h = model.History(name=h.name + "-other", user=h.user) sa_session.add(other_h) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() hc3 = hc2.copy(element_destination=other_h) other_h.add_pending_items() @@ -567,8 +552,7 @@ def test_export_copied_objects_copied_outside_history(): hc4 = hc3.copy(element_destination=h) sa_session.add(hc4) h.add_pending_items() - with transaction(sa_session): - sa_session.commit() + sa_session.commit() assert h.hid_counter == 10 @@ -610,8 +594,7 @@ def test_export_collection_hids(): sa_session.add(d1) sa_session.add(d2) sa_session.add(hc1) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() imported_history = _import_export(app, h) @@ -673,13 +656,10 @@ def _import_export(app, h, dest_export=None): dest_export = os.path.join(dest_parent, "moo.tgz") job = model.Job() - app.model.session.add(job, h) session = app.model.session - with transaction(session): - session.commit() - jeha = model.JobExportHistoryArchive.create_for_history( - h, job, app.model.context, app.object_store, compressed=True - ) + session.add(job, h) + session.commit() + jeha = model.JobExportHistoryArchive.create_for_history(h, job, session, app.object_store, compressed=True) wrapper = JobExportHistoryArchiveWrapper(app, job.id) wrapper.setup_job(h, jeha.temp_directory) diff --git a/test/unit/app/tools/test_metadata.py b/test/unit/app/tools/test_metadata.py index 8f83c6b90ef6..e4786910e7ea 100644 --- a/test/unit/app/tools/test_metadata.py +++ b/test/unit/app/tools/test_metadata.py @@ -5,7 +5,6 @@ from galaxy.app_unittest_utils import tools_support from galaxy.job_execution.datasets import DatasetPath from galaxy.metadata import get_metadata_compute_strategy -from galaxy.model.base import transaction from galaxy.objectstore import ObjectStorePopulator from galaxy.util import ( galaxy_directory, @@ -24,8 +23,7 @@ def setUp(self): sa_session.add(job) history = model.History() job.history = history - with transaction(sa_session): - sa_session.commit() + sa_session.commit() self.job = job self.history = history self.job_working_directory = os.path.join(self.test_directory, "job_working") @@ -52,8 +50,7 @@ def _test_simple_output(self): extension="fasta", ) sa_session = self.app.model.session - with transaction(sa_session): - sa_session.commit() + sa_session.commit() output_datasets = { "out_file1": output_dataset, } @@ -85,8 +82,7 @@ def _test_primary_dataset_output_extension(self): extension="auto", ) sa_session = self.app.model.session - with transaction(sa_session): - sa_session.commit() + sa_session.commit() output_datasets = { "out_file1": output_dataset, } @@ -124,8 +120,7 @@ def _test_primary_dataset_output_metadata_override(self): extension="auto", ) sa_session = self.app.model.session - with transaction(sa_session): - sa_session.commit() + sa_session.commit() output_datasets = { "out_file1": output_dataset, } @@ -169,10 +164,9 @@ def _create_output_dataset_collection(self, **kwd): output_dataset_collection = model.HistoryDatasetCollectionAssociation(**kwd) self.history.add_dataset_collection(output_dataset_collection) assert output_dataset_collection.collection - self.app.model.session.add(output_dataset_collection) session = self.app.model.session - with transaction(session): - session.commit() + session.add(output_dataset_collection) + session.commit() return output_dataset_collection def _create_output_dataset(self, **kwd): diff --git a/test/unit/app/tools/test_select_parameters.py b/test/unit/app/tools/test_select_parameters.py index 656325490a95..30b025137e2b 100644 --- a/test/unit/app/tools/test_select_parameters.py +++ b/test/unit/app/tools/test_select_parameters.py @@ -3,7 +3,6 @@ import pytest from galaxy import model -from galaxy.model.base import transaction from galaxy.tools.parameters.workflow_utils import RuntimeValue from .util import BaseParameterTestCase @@ -57,10 +56,9 @@ def test_filter_param_value2(self): def setUp(self): super().setUp() self.test_history = model.History() - self.app.model.context.add(self.test_history) session = self.app.model.context - with transaction(session): - session.commit() + session.add(self.test_history) + session.commit() self.app.tool_data_tables["test_table"] = MockToolDataTable() self.trans = Mock( app=self.app, diff --git a/test/unit/app/tools/test_tool_shed_repository_cache.py b/test/unit/app/tools/test_tool_shed_repository_cache.py index 9ddfd6489df2..2a5a5c4312f5 100644 --- a/test/unit/app/tools/test_tool_shed_repository_cache.py +++ b/test/unit/app/tools/test_tool_shed_repository_cache.py @@ -1,6 +1,5 @@ import pytest -from galaxy.model.base import transaction from .conftest import create_repo @@ -24,10 +23,9 @@ def test_add_repository_and_tool_conf_repository_to_repository_cache( tool_shed_repository_cache._build() assert len(tool_shed_repository_cache.repositories) == 10 assert len(tool_shed_repository_cache.local_repositories) == 10 - create_repo(tool_shed_repository_cache.session, "21", "20") session = tool_shed_repository_cache.session - with transaction(session): - session.commit() + create_repo(session, "21", "20") + session.commit() tool_shed_repository_cache._build() assert len(tool_shed_repository_cache.repositories) == 11 assert len(tool_shed_repository_cache.local_repositories) == 10 diff --git a/test/unit/app/tools/test_toolbox.py b/test/unit/app/tools/test_toolbox.py index f4faaa370a1a..555226d21947 100644 --- a/test/unit/app/tools/test_toolbox.py +++ b/test/unit/app/tools/test_toolbox.py @@ -6,7 +6,6 @@ from galaxy import model from galaxy.app_unittest_utils.toolbox_support import BaseToolBoxTestCase -from galaxy.model.base import transaction from galaxy.tool_util.unittest_utils import mock_trans from galaxy.tool_util.unittest_utils.sample_data import ( SIMPLE_MACRO, @@ -360,11 +359,10 @@ def __test_workflow(self): user.email = "test@example.com" user.password = "passw0rD1" stored_workflow.user = user - self.app.model.context.add(workflow) - self.app.model.context.add(stored_workflow) session = self.app.model.context - with transaction(session): - session.commit() + session.add(workflow) + session.add(stored_workflow) + session.commit() return stored_workflow def __verify_two_test_tools(self): From 62155b9512192da9cb5e9dde6c04740710650f20 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 14:04:29 -0500 Subject: [PATCH 07/39] Remove transaction helper from test.integration --- test/integration/oidc/test_auth_oidc.py | 7 ++----- test/integration/test_job_files.py | 14 ++++---------- test/integration/test_local_job_cancellation.py | 4 +--- test/integration/test_repository_operations.py | 8 +++----- test/integration/test_workflow_refactoring.py | 7 ++----- 5 files changed, 12 insertions(+), 28 deletions(-) diff --git a/test/integration/oidc/test_auth_oidc.py b/test/integration/oidc/test_auth_oidc.py index 07169ca6fc78..3725cfb42b32 100644 --- a/test/integration/oidc/test_auth_oidc.py +++ b/test/integration/oidc/test_auth_oidc.py @@ -10,7 +10,6 @@ from typing import ClassVar from urllib import parse -from galaxy.model.base import transaction from galaxy.util import requests from galaxy_test.base.api import ApiTestInteractor from galaxy_test.driver import integration_util @@ -211,8 +210,7 @@ def test_oidc_login_existing_user(self): user.set_password_cleartext("test123") sa_session.add(user) try: - with transaction(sa_session): - sa_session.commit() + sa_session.commit() except Exception: # User already exists pass @@ -237,8 +235,7 @@ def test_oidc_login_account_linkup(self): user.set_password_cleartext("test123") sa_session.add(user) try: - with transaction(sa_session): - sa_session.commit() + sa_session.commit() except Exception: # User already exists pass diff --git a/test/integration/test_job_files.py b/test/integration/test_job_files.py index fce3bf4bd6bd..4f244419156b 100644 --- a/test/integration/test_job_files.py +++ b/test/integration/test_job_files.py @@ -25,10 +25,7 @@ from tusclient import client from galaxy import model -from galaxy.model.base import ( - ensure_object_added_to_session, - transaction, -) +from galaxy.model.base import ensure_object_added_to_session from galaxy_test.base import api_asserts from galaxy_test.base.populators import DatasetPopulator from galaxy_test.driver import integration_util @@ -190,8 +187,7 @@ def create_static_job_with_state(self, state): output_hda = model.HistoryDatasetAssociation(history=history, create_dataset=True, flush=False) output_hda.hid = 2 sa_session.add(output_hda) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() job = model.Job() job.history = history ensure_object_added_to_session(job, object_in_session=history) @@ -201,8 +197,7 @@ def create_static_job_with_state(self, state): sa_session.add(job) job.add_input_dataset("input1", hda) job.add_output_dataset("output1", output_hda) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() self._app.object_store.create(output_hda.dataset) self._app.object_store.create(job, base_dir="job_work", dir_only=True, obj_dir=True) working_directory = self._app.object_store.get_filename(job, base_dir="job_work", dir_only=True, obj_dir=True) @@ -218,8 +213,7 @@ def _change_job_state(self, job, state): job.state = state sa_session = self.sa_session sa_session.add(job) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() def _assert_insufficient_permissions(response): diff --git a/test/integration/test_local_job_cancellation.py b/test/integration/test_local_job_cancellation.py index 888a62b662c0..9394fceac43e 100644 --- a/test/integration/test_local_job_cancellation.py +++ b/test/integration/test_local_job_cancellation.py @@ -5,7 +5,6 @@ import psutil from sqlalchemy import select -from galaxy.model.base import transaction from galaxy_test.base.populators import DatasetPopulator from galaxy_test.driver import integration_util @@ -51,8 +50,7 @@ def test_cancel_job_with_admin_message(self): job.job_stderr = "admin cancelled job" job.set_state(Job.states.DELETING) sa_session.add(job) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() self.galaxy_interactor.wait_for( lambda: self._get(f"jobs/{job_id}").json()["state"] != "error", what="Wait for job to end in error", diff --git a/test/integration/test_repository_operations.py b/test/integration/test_repository_operations.py index 510067db9660..3bdfbc039bbf 100644 --- a/test/integration/test_repository_operations.py +++ b/test/integration/test_repository_operations.py @@ -3,7 +3,6 @@ from sqlalchemy import select -from galaxy.model.base import transaction from galaxy_test.base.populators import DatasetPopulator from galaxy_test.driver import integration_util from galaxy_test.driver.uses_shed import UsesShed @@ -87,16 +86,15 @@ def test_repository_update(self): hg_util.update_repository(repository_path, ctx_rev="3") # change repo to revision 3 in database model = self._app.install_model - tsr = model.session.scalars(select(model.ToolShedRepository).limit(1)).first() + session = model.context() + tsr = session.scalars(select(model.ToolShedRepository).limit(1)).first() assert tsr.name == REPO.name assert tsr.changeset_revision == latest_revision assert int(tsr.ctx_rev) >= 4 tsr.ctx_rev = "3" tsr.installed_changeset_revision = REVISION_3 tsr.changeset_revision = REVISION_3 - session = model.context - with transaction(session): - session.commit() + session.commit() # update shed_tool_conf.xml to look like revision 3 was the installed_changeset_revision with open(self._app.config.shed_tool_config_file) as shed_config: shed_text = shed_config.read().replace(latest_revision, REVISION_3) diff --git a/test/integration/test_workflow_refactoring.py b/test/integration/test_workflow_refactoring.py index d68b8916145b..a964dbb0fb2a 100644 --- a/test/integration/test_workflow_refactoring.py +++ b/test/integration/test_workflow_refactoring.py @@ -20,7 +20,6 @@ WorkflowStep, WorkflowStepConnection, ) -from galaxy.model.base import transaction from galaxy.tools.parameters.workflow_utils import workflow_building_modes from galaxy.workflow.refactor.schema import RefactorActionExecutionMessageTypeEnum from galaxy_test.base.populators import WorkflowPopulator @@ -822,8 +821,7 @@ def _dry_run(self, actions: ActionsJson, stored_workflow=None): # Do a bunch of checks to ensure nothing workflow related was written to the database # or even added to the sa_session. sa_session = self._app.model.session - with transaction(sa_session): - sa_session.commit() + sa_session.commit() sw_update_time = self._model_last_time(StoredWorkflow) assert sw_update_time @@ -837,8 +835,7 @@ def _dry_run(self, actions: ActionsJson, stored_workflow=None): wo_last_id = self._model_last_id(WorkflowOutput) response = self._refactor(actions, stored_workflow=stored_workflow, dry_run=True) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() assert sw_update_time == self._model_last_time(StoredWorkflow) assert w_update_time == self._model_last_time(Workflow) assert ws_last_id == self._model_last_id(WorkflowStep) From 896d0848c25fb667c4eceda976616242fa9ebbea Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 14:18:40 -0500 Subject: [PATCH 08/39] Remove transaction helper from scripts --- .../admin_cleanup_datasets.py | 5 +- scripts/cleanup_datasets/cleanup_datasets.py | 94 ++++++++----------- scripts/cleanup_datasets/populate_uuid.py | 11 +-- scripts/pages_identifier_conversion.py | 7 +- scripts/set_dataset_sizes.py | 11 +-- ...deprecate_repositories_without_metadata.py | 4 +- scripts/update_shed_config_path.py | 4 +- 7 files changed, 54 insertions(+), 82 deletions(-) diff --git a/scripts/cleanup_datasets/admin_cleanup_datasets.py b/scripts/cleanup_datasets/admin_cleanup_datasets.py index 336f8227890f..229563ee686f 100755 --- a/scripts/cleanup_datasets/admin_cleanup_datasets.py +++ b/scripts/cleanup_datasets/admin_cleanup_datasets.py @@ -64,7 +64,6 @@ import galaxy.config import galaxy.model.mapping import galaxy.util -from galaxy.model.base import transaction from galaxy.util.script import ( app_properties_from_args, populate_config_args, @@ -261,9 +260,7 @@ def administrative_delete_datasets( hda.deleted = True app.sa_session.add(hda) print(f"Marked HistoryDatasetAssociation id {hda.id} as deleted") - session = app.sa_session() - with transaction(session): - session.commit() + app.session().commit() emailtemplate = Template(filename=template_file) for email, dataset_list in user_notifications.items(): diff --git a/scripts/cleanup_datasets/cleanup_datasets.py b/scripts/cleanup_datasets/cleanup_datasets.py index 81fd7801f5da..5cd7330ea7ea 100755 --- a/scripts/cleanup_datasets/cleanup_datasets.py +++ b/scripts/cleanup_datasets/cleanup_datasets.py @@ -26,7 +26,6 @@ import galaxy.config from galaxy.datatypes.registry import Registry from galaxy.exceptions import ObjectNotFound -from galaxy.model.base import transaction from galaxy.model.mapping import init_models_from_config from galaxy.objectstore import build_object_store_from_config from galaxy.util import unicodify @@ -222,12 +221,13 @@ def delete_userless_histories(app, cutoff_time, info_only=False, force_retry=Fal # Nothing is removed from disk yet. history_count = 0 start = time.time() + session = app.sa_session() if force_retry: - histories = app.sa_session.query(app.model.History).filter( + histories = session.query(app.model.History).filter( and_(app.model.History.__table__.c.user_id == null(), app.model.History.update_time < cutoff_time) ) else: - histories = app.sa_session.query(app.model.History).filter( + histories = session.query(app.model.History).filter( and_( app.model.History.__table__.c.user_id == null(), app.model.History.__table__.c.deleted == false(), @@ -238,10 +238,8 @@ def delete_userless_histories(app, cutoff_time, info_only=False, force_retry=Fal if not info_only: log.info("Deleting history id %d", history.id) history.deleted = True - app.sa_session.add(history) - session = app.sa_session() - with transaction(session): - session.commit() + session.add(history) + session.commit() history_count += 1 stop = time.time() log.info("Deleted %d histories", history_count) @@ -257,15 +255,16 @@ def purge_histories(app, cutoff_time, remove_from_disk, info_only=False, force_r # i.e. all associated datasets are marked as deleted history_count = 0 start = time.time() + session = app.sa_session() if force_retry: histories = ( - app.sa_session.query(app.model.History) + session.query(app.model.History) .filter(and_(app.model.History.__table__.c.deleted == true(), app.model.History.update_time < cutoff_time)) .options(joinedload(app.model.History.datasets)) ) else: histories = ( - app.sa_session.query(app.model.History) + session.query(app.model.History) .filter( and_( app.model.History.__table__.c.deleted == true(), @@ -289,10 +288,8 @@ def purge_histories(app, cutoff_time, remove_from_disk, info_only=False, force_r # dhp.delete() log.info("Purging history id %d", history.id) history.purged = True - app.sa_session.add(history) - session = app.sa_session() - with transaction(session): - session.commit() + session.add(history) + session.commit() else: log.info("History id %d will be purged (without 'info_only' mode)", history.id) history_count += 1 @@ -310,14 +307,15 @@ def purge_libraries(app, cutoff_time, remove_from_disk, info_only=False, force_r # i.e. all associated LibraryDatasets/folders are marked as deleted library_count = 0 start = time.time() + session = app.sa_session() if force_retry: - libraries = app.sa_session.query(app.model.Library).filter( + libraries = session.query(app.model.Library).filter( and_( app.model.Library.__table__.c.deleted == true(), app.model.Library.__table__.c.update_time < cutoff_time ) ) else: - libraries = app.sa_session.query(app.model.Library).filter( + libraries = session.query(app.model.Library).filter( and_( app.model.Library.__table__.c.deleted == true(), app.model.Library.__table__.c.purged == false(), @@ -329,10 +327,8 @@ def purge_libraries(app, cutoff_time, remove_from_disk, info_only=False, force_r if not info_only: log.info("Purging library id %d", library.id) library.purged = True - app.sa_session.add(library) - session = app.sa_session() - with transaction(session): - session.commit() + session.add(library) + session.commit() library_count += 1 stop = time.time() log.info("# Purged %d libraries .", library_count) @@ -413,6 +409,7 @@ def delete_datasets(app, cutoff_time, remove_from_disk, info_only=False, force_r deleted_dataset_count = 0 deleted_instance_count = 0 skip = [] + session = app.sa_session() # Handle library datasets. This is a bit tricky, so here's some clarification. We have a list of all # LibraryDatasets that were marked deleted before our cutoff_time, but have not yet been marked purged. # A LibraryDataset object is marked purged when all of its LibraryDatasetDatasetAssociations have been @@ -421,37 +418,35 @@ def delete_datasets(app, cutoff_time, remove_from_disk, info_only=False, force_r # and add it to our accrued list of Datasets for later processing. We mark as deleted all of its # LibraryDatasetDatasetAssociations. Then we mark the LibraryDataset as purged. We then process our # list of Datasets. - library_dataset_ids = [row.id for row in app.sa_session.execute(library_dataset_ids_query)] + library_dataset_ids = [row.id for row in session.execute(library_dataset_ids_query)] dataset_ids = [] for library_dataset_id in library_dataset_ids: log.info("######### Processing LibraryDataset id: %d", library_dataset_id) # Get the LibraryDataset and the current LibraryDatasetDatasetAssociation objects - ld = app.sa_session.query(app.model.LibraryDataset).get(library_dataset_id) + ld = session.query(app.model.LibraryDataset).get(library_dataset_id) ldda = ld.library_dataset_dataset_association # Append the associated Dataset object's id to our list of dataset_ids dataset_ids.append(ldda.dataset_id) # Mark all of the LibraryDataset's associated LibraryDatasetDatasetAssociation objects' as deleted if not ldda.deleted: ldda.deleted = True - app.sa_session.add(ldda) + session.add(ldda) log.info("Marked associated LibraryDatasetDatasetAssociation id %d as deleted", ldda.id) for expired_ldda in ld.expired_datasets: if not expired_ldda.deleted: expired_ldda.deleted = True - app.sa_session.add(expired_ldda) + session.add(expired_ldda) log.info("Marked associated expired LibraryDatasetDatasetAssociation id %d as deleted", ldda.id) # Mark the LibraryDataset as purged ld.purged = True - app.sa_session.add(ld) + session.add(ld) log.info("Marked LibraryDataset id %d as purged", ld.id) - session = app.sa_session() - with transaction(session): - session.commit() + session.commit() # Add all datasets associated with Histories to our list - dataset_ids.extend([row.id for row in app.sa_session.execute(history_dataset_ids_query)]) + dataset_ids.extend([row.id for row in session.execute(history_dataset_ids_query)]) # Process each of the Dataset objects for dataset_id in dataset_ids: - dataset = app.sa_session.query(app.model.Dataset).get(dataset_id) + dataset = session.query(app.model.Dataset).get(dataset_id) if dataset.id in skip: continue skip.append(dataset.id) @@ -528,10 +523,9 @@ def _purge_dataset_instance(dataset_instance, app, remove_from_disk, info_only=F ) dataset_instance.mark_deleted() dataset_instance.clear_associated_files() - app.sa_session.add(dataset_instance) session = app.sa_session() - with transaction(session): - session.commit() + session.add(dataset_instance) + session.commit() app.sa_session.refresh(dataset_instance.dataset) else: log.info( @@ -572,12 +566,12 @@ def _delete_dataset(dataset, app, remove_from_disk, info_only=False, is_deletabl metadata_files = [] # lets create a list of metadata files, then perform actions on them for hda in dataset.history_associations: - for metadata_file in app.sa_session.query(app.model.MetadataFile).filter( + for metadata_file in session.query(app.model.MetadataFile).filter( app.model.MetadataFile.__table__.c.hda_id == hda.id ): metadata_files.append(metadata_file) for ldda in dataset.library_associations: - for metadata_file in app.sa_session.query(app.model.MetadataFile).filter( + for metadata_file in session.query(app.model.MetadataFile).filter( app.model.MetadataFile.__table__.c.lda_id == ldda.id ): metadata_files.append(metadata_file) @@ -608,20 +602,17 @@ def _delete_dataset(dataset, app, remove_from_disk, info_only=False, is_deletabl metadata_file.get_file_name(), ) metadata_file.purged = True - app.sa_session.add(metadata_file) - with transaction(session): - session.commit() - metadata_file.deleted = True - app.sa_session.add(metadata_file) - with transaction(session): + session.add(metadata_file) session.commit() + metadata_file.deleted = True + session.add(metadata_file) + session.commit() log.info(metadata_file.get_file_name()) if not info_only: log.info("Deleting dataset id %d", dataset.id) dataset.deleted = True - app.sa_session.add(dataset) - with transaction(session): - session.commit() + session.add(dataset) + session.commit() else: log.info("Dataset %d will be deleted (without 'info_only' mode)", dataset.id) @@ -650,12 +641,11 @@ def _purge_dataset(app, dataset, remove_from_disk, info_only=False): usage_users.append(hda.history.user) for user in usage_users: user.adjust_total_disk_usage(-dataset.get_total_size()) - app.sa_session.add(user) + session.add(user) log.info("Purging dataset id %d", dataset.id) dataset.purged = True - app.sa_session.add(dataset) - with transaction(session): - session.commit() + session.add(dataset) + session.commit() else: log.info("Dataset %d will be purged (without 'info_only' mode)", dataset.id) else: @@ -668,9 +658,8 @@ def _purge_dataset(app, dataset, remove_from_disk, info_only=False): log.error("Error, dataset file has already been removed: %s", unicodify(exc)) log.error("Purging dataset id %d", dataset.id) dataset.purged = True - app.sa_session.add(dataset) - with transaction(session): - session.commit() + session.add(dataset) + session.commit() except ObjectNotFound: log.error("Dataset %d cannot be found in the object store", dataset.id) except Exception as exc: @@ -694,10 +683,9 @@ def _purge_folder(folder, app, remove_from_disk, info_only=False): # TODO: should the folder permissions be deleted here? log.info("Purging folder id %s", folder.id) folder.purged = True - app.sa_session.add(folder) session = app.sa_session() - with transaction(session): - session.commit() + session.add(folder) + session.commit() class CleanupDatasetsApplication: diff --git a/scripts/cleanup_datasets/populate_uuid.py b/scripts/cleanup_datasets/populate_uuid.py index 64614fe264f0..6d8f56003d50 100755 --- a/scripts/cleanup_datasets/populate_uuid.py +++ b/scripts/cleanup_datasets/populate_uuid.py @@ -15,7 +15,6 @@ sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, "lib"))) import galaxy.config -from galaxy.model.base import transaction from galaxy.model.mapping import init_models_from_config from galaxy.util.script import ( app_properties_from_args, @@ -40,19 +39,17 @@ def main(): model = init_models_from_config(config) session = model.context() - for row in model.context.query(model.Dataset): + for row in session.query(model.Dataset): if row.uuid is None: row.uuid = uuid.uuid4() print("Setting dataset:", row.id, " UUID to ", row.uuid) - with transaction(session): - session.commit() + session.commit() - for row in model.context.query(model.Workflow): + for row in session.query(model.Workflow): if row.uuid is None: row.uuid = uuid.uuid4() print("Setting Workflow:", row.id, " UUID to ", row.uuid) - with transaction(session): - session.commit() + session.commit() print("Complete") diff --git a/scripts/pages_identifier_conversion.py b/scripts/pages_identifier_conversion.py index 8aaee5f2247c..08a571f0995d 100644 --- a/scripts/pages_identifier_conversion.py +++ b/scripts/pages_identifier_conversion.py @@ -13,7 +13,6 @@ PageContentProcessor, placeholderRenderForSave, ) -from galaxy.model.base import transaction from galaxy.model.mapping import init_models_from_config from galaxy.objectstore import build_object_store_from_config from galaxy.security.idencoding import IdEncodingHelper @@ -42,7 +41,7 @@ def main(argv): ) model = init_models_from_config(config, object_store=object_store) - session = model.context.current + session = model.context.current() pagerevs = session.query(model.PageRevision).all() mock_trans = Bunch(app=Bunch(security=security_helper), model=model, user_is_admin=lambda: True, sa_session=session) for p in pagerevs: @@ -54,9 +53,7 @@ def main(argv): if not args.dry_run: p.content = unicodify(processor.output(), "utf-8") session.add(p) - session = session() - with transaction(session): - session.commit() + session.commit() else: print(f"Modifying revision {p.id}.") print(difflib.unified_diff(p.content, newcontent)) diff --git a/scripts/set_dataset_sizes.py b/scripts/set_dataset_sizes.py index d420141ad0c5..0e235af24e1a 100644 --- a/scripts/set_dataset_sizes.py +++ b/scripts/set_dataset_sizes.py @@ -7,7 +7,6 @@ sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "lib"))) import galaxy.config -from galaxy.model.base import transaction from galaxy.model.mapping import init_models_from_config from galaxy.objectstore import build_object_store_from_config from galaxy.util.script import ( @@ -36,24 +35,22 @@ def init(): session = sa_session() set = 0 - dataset_count = sa_session.query(model.Dataset).count() + dataset_count = session.query(model.Dataset).count() print(f"Processing {dataset_count} datasets...") percent = 0 print(f"Completed {percent}%", end=" ") sys.stdout.flush() - for i, dataset in enumerate(sa_session.query(model.Dataset).enable_eagerloads(False).yield_per(1000)): + for i, dataset in enumerate(session.query(model.Dataset).enable_eagerloads(False).yield_per(1000)): if dataset.total_size is None: dataset.set_total_size() set += 1 if not set % 1000: - with transaction(session): - session.commit() + session.commit() new_percent = int(float(i) / dataset_count * 100) if new_percent != percent: percent = new_percent print(f"\rCompleted {percent}%", end=" ") sys.stdout.flush() - with transaction(session): - session.commit() + session.commit() print("\rCompleted 100%") object_store.shutdown() diff --git a/scripts/tool_shed/deprecate_repositories_without_metadata.py b/scripts/tool_shed/deprecate_repositories_without_metadata.py index f03284941b0a..badb49ad3725 100644 --- a/scripts/tool_shed/deprecate_repositories_without_metadata.py +++ b/scripts/tool_shed/deprecate_repositories_without_metadata.py @@ -26,7 +26,6 @@ import tool_shed.webapp.config as tool_shed_config import tool_shed.webapp.model.mapping -from galaxy.model.base import transaction from galaxy.util import ( build_url, send_mail as galaxy_send_mail, @@ -176,8 +175,7 @@ def deprecate_repositories(app, cutoff_time, days=14, info_only=False, verbose=F repository.deprecated = True app.sa_session.add(repository) session = app.sa_session() - with transaction(session): - session.commit() + session.commit() owner = repositories_by_owner[repository_owner]["owner"] send_mail_to_owner( app, owner.username, owner.email, repositories_by_owner[repository_owner]["repositories"], days diff --git a/scripts/update_shed_config_path.py b/scripts/update_shed_config_path.py index a5bee3af9f63..d7163826bf36 100644 --- a/scripts/update_shed_config_path.py +++ b/scripts/update_shed_config_path.py @@ -15,7 +15,6 @@ sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "lib"))) import galaxy.model.tool_shed_install.mapping as mapping -from galaxy.model.base import transaction def main(opts, session, model): @@ -27,8 +26,7 @@ def main(opts, session, model): if row.metadata_["shed_config_filename"] == opts.bad_filename: row.metadata_["shed_config_filename"] = opts.good_filename session.add(row) - with transaction(session): - session.commit() + session.commit() return 0 From 7886de0dd865499ae7d83b029639ff6d3f9dc6a2 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 14:57:06 -0500 Subject: [PATCH 09/39] Fix typo Co-authored-by: Nicola Soranzo --- scripts/cleanup_datasets/admin_cleanup_datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cleanup_datasets/admin_cleanup_datasets.py b/scripts/cleanup_datasets/admin_cleanup_datasets.py index 229563ee686f..81b65c5a8373 100755 --- a/scripts/cleanup_datasets/admin_cleanup_datasets.py +++ b/scripts/cleanup_datasets/admin_cleanup_datasets.py @@ -260,7 +260,7 @@ def administrative_delete_datasets( hda.deleted = True app.sa_session.add(hda) print(f"Marked HistoryDatasetAssociation id {hda.id} as deleted") - app.session().commit() + app.sa_session().commit() emailtemplate = Template(filename=template_file) for email, dataset_list in user_notifications.items(): From 79f44a21281fd7751274afe9b070de055681d3b4 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 16:03:30 -0500 Subject: [PATCH 10/39] Remove transaction helper from galaxy.security --- lib/galaxy/security/vault.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/security/vault.py b/lib/galaxy/security/vault.py index 23c48a16423d..9782ed276ece 100644 --- a/lib/galaxy/security/vault.py +++ b/lib/galaxy/security/vault.py @@ -31,7 +31,6 @@ hvac = None from galaxy import model -from galaxy.model.base import transaction log = logging.getLogger(__name__) @@ -149,8 +148,7 @@ def _update_or_create(self, key: str, value: Optional[str]) -> model.Vault: if value: vault_entry.value = value self.sa_session.merge(vault_entry) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() else: # recursively create parent keys parent_key, _, _ = key.rpartition("/") @@ -158,8 +156,7 @@ def _update_or_create(self, key: str, value: Optional[str]) -> model.Vault: self._update_or_create(parent_key, None) vault_entry = model.Vault(key=key, value=value, parent_key=parent_key or None) self.sa_session.merge(vault_entry) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return vault_entry def read_secret(self, key: str) -> Optional[str]: From 65756664d689f37d966150f3791d4864536c0f69 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 16:15:30 -0500 Subject: [PATCH 11/39] Remove transaction helper from galaxy.model --- lib/galaxy/model/__init__.py | 105 ++++++++++------------------- lib/galaxy/model/deferred.py | 4 +- lib/galaxy/model/item_attrs.py | 10 +-- lib/galaxy/model/metadata.py | 7 +- lib/galaxy/model/security.py | 49 +++++--------- lib/galaxy/model/store/__init__.py | 11 +-- lib/galaxy/model/tags.py | 10 +-- 7 files changed, 62 insertions(+), 134 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 6953aa2b66e3..c336bc8b68ee 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -146,10 +146,7 @@ FileSourceTemplate, template_to_configuration as file_source_template_to_configuration, ) -from galaxy.model.base import ( - ensure_object_added_to_session, - transaction, -) +from galaxy.model.base import ensure_object_added_to_session from galaxy.model.custom_types import ( DoubleEncodedJsonType, JSONType, @@ -1164,8 +1161,7 @@ def _calculate_or_set_disk_usage(self, object_store): # the existing value - we're setting it in raw SQL for # performance reasons and bypassing object properties. sa_session.expire(self, ["disk_usage"]) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() @staticmethod def user_template_environment(user: Optional["User"]): @@ -1234,8 +1230,7 @@ def attempt_create_private_role(self): role = Role(type=Role.types.PRIVATE) assoc = UserRoleAssociation(self, role) session.add(assoc) - with transaction(session): - session.commit() + session.commit() def dictify_objectstore_usage(self) -> List[UserObjectstoreUsage]: session = object_session(self) @@ -1941,8 +1936,7 @@ def resume(self, flush=True): job.resume(flush=False) if flush: session = object_session(self) - with transaction(session): - session.commit() + session.commit() def _serialize(self, id_encoder, serialization_options): job_attrs = dict_for(self) @@ -2209,8 +2203,7 @@ def hide_outputs(self, flush=True): output_association.item.visible = False if flush: session = object_session(self) - with transaction(session): - session.commit() + session.commit() class Task(Base, JobLike, RepresentById): @@ -2815,8 +2808,7 @@ def create_for_history(history, job, sa_session, object_store, compressed): archive_dataset = Dataset() sa_session.add(archive_dataset) - with transaction(sa_session): - sa_session.commit() # ensure job.id and archive_dataset.id are available + sa_session.commit() # ensure job.id and archive_dataset.id are available object_store.create(archive_dataset) # set the object store id, create dataset (if applicable) # Add association for keeping track of job, history, archive relationship. @@ -3382,8 +3374,7 @@ def add_dataset(self, dataset, parent_id=None, genome_build=None, set_hid=True, object_session(self).add(dataset) session = object_session(self) - with transaction(session): - session.commit() + session.commit() elif not isinstance(dataset, (HistoryDatasetAssociation, HistoryDatasetCollectionAssociation)): raise TypeError( @@ -3430,15 +3421,13 @@ def add_datasets( self.user.adjust_total_disk_usage(disk_usage, quota_source_info.label) sa_session.add_all(datasets) if flush: - with transaction(sa_session): - sa_session.commit() + sa_session.commit() else: for dataset in datasets: self.add_dataset(dataset, parent_id=parent_id, genome_build=genome_build, set_hid=set_hid, quota=quota) sa_session.add(dataset) if flush: - with transaction(sa_session): - sa_session.commit() + sa_session.commit() def __add_datasets_optimized(self, datasets, genome_build=None): """Optimized version of add_dataset above that minimizes database @@ -3517,8 +3506,7 @@ def copy(self, name=None, target_user=None, activatable=False, all_datasets=Fals new_hdca.copy_tags_from(target_user, hdca) new_history.hid_counter = self.hid_counter - with transaction(db_session): - db_session.commit() + db_session.commit() return new_history @@ -3575,8 +3563,7 @@ def resume_paused_jobs(self): if job is not None: # We'll flush once if there was a paused job session = object_session(job) - with transaction(session): - session.commit() + session.commit() @property def paused_jobs(self): @@ -4131,8 +4118,7 @@ def __init__(self, history, action, role): class StorableObject: def flush(self): if sa_session := object_session(self): - with transaction(sa_session): - sa_session.commit() + sa_session.commit() def setup_global_object_store_for_models(object_store: "BaseObjectStore") -> None: @@ -4420,8 +4406,7 @@ def get_total_size(self): # for backwards compatibility, set if unset self.set_total_size() db_session = object_session(self) - with transaction(db_session): - db_session.commit() + db_session.commit() return self.total_size def set_total_size(self): @@ -4721,8 +4706,7 @@ def __init__( dataset.job_id = creating_job_id if flush: sa_session.add(dataset) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() elif dataset: add_object_to_object_session(self, dataset) self.dataset = dataset @@ -5428,8 +5412,7 @@ def copy(self, parent_id=None, copy_tags=None, flush=True, copy_hid=True, new_na hda.metadata = self.metadata if flush: session = object_session(self) - with transaction(session): - session.commit() + session.commit() return hda def copy_tags_to(self, copy_tags=None): @@ -5499,8 +5482,7 @@ def to_library_dataset_dataset_association( trans.sa_session.add(dp) # Must set metadata after ldda flushed, as MetadataFiles require ldda.id if self.set_metadata_requires_flush: - with transaction(session): - session.commit() + session.commit() ldda.metadata = self.metadata # TODO: copy #tags from history if ldda_message: @@ -5509,9 +5491,7 @@ def to_library_dataset_dataset_association( target_folder.add_library_dataset(library_dataset, genome_build=ldda.dbkey) session.add(target_folder) session.add(library_dataset) - - with transaction(session): - session.commit() + session.commit() return ldda @@ -6140,8 +6120,7 @@ def to_history_dataset_association( if commit: target_history.add_pending_items() if commit: - with transaction(sa_session): - sa_session.commit() + sa_session.commit() return hda def copy(self, parent_id=None, target_folder=None, flush=True): @@ -6167,12 +6146,10 @@ def copy(self, parent_id=None, target_folder=None, flush=True): tag_manager.apply_item_tags(user=self.user, item=ldda, tags_str=src_ldda_tags) sa_session.add(ldda) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() # Need to set after flushed, as MetadataFiles require dataset.id ldda.metadata = self.metadata - with transaction(sa_session): - sa_session.commit() + sa_session.commit() return ldda def clear_associated_files(self, metadata_safe=False, purge=False): @@ -6882,8 +6859,7 @@ def copy( object_session(self).add(new_collection) if flush: session = object_session(self) - with transaction(session): - session.commit() + session.commit() return new_collection def replace_failed_elements(self, replacements): @@ -7314,8 +7290,7 @@ def copy( element_destination.add_pending_items() if flush: session = object_session(self) - with transaction(session): - session.commit() + session.commit() return hdca @property @@ -10102,8 +10077,7 @@ class PSAAssociation(Base, AssociationMixin, RepresentById): def save(self): self.sa_session.add(self) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() @classmethod def store(cls, server_url, association): @@ -10123,8 +10097,7 @@ def get_or_create(): assoc.lifetime = association.lifetime assoc.assoc_type = association.assoc_type cls.sa_session.add(assoc) - with transaction(cls.sa_session): - cls.sa_session.commit() + cls.sa_session.commit() @classmethod def get(cls, *args, **kwargs): @@ -10166,8 +10139,7 @@ def __init__(self, email, code): def save(self): self.sa_session.add(self) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() @classmethod def get_code(cls, code): @@ -10196,8 +10168,7 @@ def __init__(self, server_url, timestamp, salt): def save(self): self.sa_session.add(self) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() @classmethod def use(cls, server_url, timestamp, salt): @@ -10211,8 +10182,7 @@ def use(cls, server_url, timestamp, salt): except IndexError: instance = cls(server_url=server_url, timestamp=timestamp, salt=salt) cls.sa_session.add(instance) - with transaction(cls.sa_session): - cls.sa_session.commit() + cls.sa_session.commit() return instance @@ -10236,8 +10206,7 @@ def __init__(self, token, data, next_step, backend): def save(self): self.sa_session.add(self) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() @classmethod def load(cls, token): @@ -10255,8 +10224,7 @@ def destroy(cls, token): if partial := cls.load(token): session = cls.sa_session session.execute(delete(partial)) - with transaction(session): - session.commit() + session.commit() class UserAuthnzToken(Base, UserMixin, RepresentById): @@ -10293,13 +10261,11 @@ def get_id_token(self, strategy): def set_extra_data(self, extra_data=None): if super().set_extra_data(extra_data): self.sa_session.add(self) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def save(self): self.sa_session.add(self) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() @classmethod def changed(cls, user): @@ -10308,8 +10274,7 @@ def changed(cls, user): (Required by social_core.storage.UserMixin interface) """ cls.sa_session.add(user) - with transaction(cls.sa_session): - cls.sa_session.commit() + cls.sa_session.commit() @classmethod def get_username(cls, user): @@ -10361,8 +10326,7 @@ def create_user(cls, *args, **kwargs): raise Exception(f"User with this email '{instance.email}' already exists.") instance.set_random_password() cls.sa_session.add(instance) - with transaction(cls.sa_session): - cls.sa_session.commit() + cls.sa_session.commit() return instance @classmethod @@ -10414,8 +10378,7 @@ def create_social_auth(cls, user, uid, provider): uid = str(uid) instance = cls(user=user, uid=uid, provider=provider) cls.sa_session.add(instance) - with transaction(cls.sa_session): - cls.sa_session.commit() + cls.sa_session.commit() return instance diff --git a/lib/galaxy/model/deferred.py b/lib/galaxy/model/deferred.py index 784e4e9a8ba3..d726834bcc52 100644 --- a/lib/galaxy/model/deferred.py +++ b/lib/galaxy/model/deferred.py @@ -32,7 +32,6 @@ HistoryDatasetCollectionAssociation, LibraryDatasetDatasetAssociation, ) -from galaxy.model.base import transaction from galaxy.objectstore import ( ObjectStore, ObjectStorePopulator, @@ -136,8 +135,7 @@ def ensure_materialized( sa_session = object_session(dataset_instance) assert sa_session sa_session.add(materialized_dataset) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() object_store_populator.set_dataset_object_store_id(materialized_dataset) try: path = self._stream_source(target_source, dataset_instance.datatype, materialized_dataset) diff --git a/lib/galaxy/model/item_attrs.py b/lib/galaxy/model/item_attrs.py index 37a467f5dde7..4e81dda02fea 100644 --- a/lib/galaxy/model/item_attrs.py +++ b/lib/galaxy/model/item_attrs.py @@ -5,7 +5,6 @@ # Cannot import galaxy.model b/c it creates a circular import graph. import galaxy -from galaxy.model.base import transaction log = logging.getLogger(__name__) @@ -47,13 +46,11 @@ def rate_item(self, db_session, user, item, rating, webapp_model=None): item_rating_assoc_class = self._get_item_rating_assoc_class(item, webapp_model=webapp_model) item_rating = item_rating_assoc_class(user, item, rating) db_session.add(item_rating) - with transaction(db_session): - db_session.commit() + db_session.commit() elif item_rating.rating != rating: # User has rated item; update rating. item_rating.rating = rating - with transaction(db_session): - db_session.commit() + db_session.commit() return item_rating def get_user_item_rating(self, db_session, user, item, webapp_model=None): @@ -98,8 +95,7 @@ def add_item_annotation(self, db_session, user, item, annotation): def delete_item_annotation(self, db_session, user, item): if annotation_assoc := get_item_annotation_obj(db_session, user, item): db_session.delete(annotation_assoc) - with transaction(db_session): - db_session.commit() + db_session.commit() def copy_item_annotation(self, db_session, source_user, source_item, target_user, target_item): """Copy an annotation from a user/item source to a user/item target.""" diff --git a/lib/galaxy/model/metadata.py b/lib/galaxy/model/metadata.py index 5fdfd8a49678..49e827416e70 100644 --- a/lib/galaxy/model/metadata.py +++ b/lib/galaxy/model/metadata.py @@ -25,7 +25,6 @@ from sqlalchemy.orm.attributes import flag_modified import galaxy.model -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.security.object_wrapper import sanitize_lists_to_string from galaxy.util import ( @@ -614,8 +613,7 @@ def wrap(self, value, session): # If we've simultaneously copied the dataset and we've changed the datatype on the # copy we may not have committed the MetadataFile yet, so we need to commit the session. # TODO: It would be great if we can avoid the commit in the future. - with transaction(session): - session.commit() + session.commit() return session.execute(select(galaxy.model.MetadataFile).filter_by(uuid=value)).scalar_one_or_none() def make_copy(self, value, target_context: MetadataCollection, source_context): @@ -636,8 +634,7 @@ def make_copy(self, value, target_context: MetadataCollection, source_context): new_value.update_from_file(value.get_file_name()) except AssertionError: tmp_session = session(target_context.parent) - with transaction(tmp_session): - tmp_session.commit() + tmp_session.commit() new_value.update_from_file(value.get_file_name()) return self.unwrap(new_value) return None diff --git a/lib/galaxy/model/security.py b/lib/galaxy/model/security.py index d3b35c046b8b..3b555daa6f87 100644 --- a/lib/galaxy/model/security.py +++ b/lib/galaxy/model/security.py @@ -49,7 +49,6 @@ UserGroupAssociation, UserRoleAssociation, ) -from galaxy.model.base import transaction from galaxy.model.db.role import ( get_npns_roles, get_private_user_role, @@ -695,29 +694,25 @@ def guess_derived_permissions(self, all_input_permissions): def associate_user_group(self, user, group): assoc = UserGroupAssociation(user, group) self.sa_session.add(assoc) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return assoc def associate_user_role(self, user, role): assoc = UserRoleAssociation(user, role) self.sa_session.add(assoc) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return assoc def associate_group_role(self, group, role): assoc = GroupRoleAssociation(group, role) self.sa_session.add(assoc) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return assoc def associate_action_dataset_role(self, action, dataset, role): assoc = DatasetPermissions(action, dataset, role) self.sa_session.add(assoc) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return assoc def create_user_role(self, user, app): @@ -769,8 +764,7 @@ def create_role(self, name, description, in_users, in_groups, create_group_for_r num_in_groups = len(in_groups) + 1 else: num_in_groups = len(in_groups) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return role, num_in_groups def get_sharing_roles(self, user): @@ -816,8 +810,7 @@ def user_set_default_permissions( self.sa_session.add(dup) flush_needed = True if flush_needed: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() if history: for history in user.active_histories: self.history_set_default_permissions( @@ -856,8 +849,7 @@ def history_set_default_permissions(self, history, permissions=None, dataset=Fal self.sa_session.add(dhp) flush_needed = True if flush_needed: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() if dataset: # Only deal with datasets that are not purged for hda in history.activatable_datasets: @@ -925,8 +917,7 @@ def set_all_dataset_permissions(self, dataset, permissions=None, new=False, flus self.sa_session.add(dp) flush_needed = True if flush_needed and flush: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return "" def set_dataset_permission(self, dataset, permission=None): @@ -955,8 +946,7 @@ def set_dataset_permission(self, dataset, permission=None): self.sa_session.add(dp) flush_needed = True if flush_needed: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def get_permissions(self, item): """ @@ -1008,8 +998,7 @@ def privately_share_dataset(self, dataset, users=None): def _create_sharing_role(self, users): sharing_role = Role(name=f"Sharing role for: {', '.join(u.email for u in users)}", type=Role.types.SHARING) self.sa_session.add(sharing_role) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() for user in users: self.associate_user_role(user, sharing_role) return sharing_role @@ -1050,8 +1039,7 @@ def set_all_library_permissions(self, trans, library_item, permissions=None): permissions[self.permitted_actions.DATASET_MANAGE_PERMISSIONS] = roles self.set_dataset_permission(library_item.dataset, permissions) if flush_needed: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def set_library_item_permission(self, library_item, permission=None): """ @@ -1078,8 +1066,7 @@ def set_library_item_permission(self, library_item, permission=None): self.sa_session.add(item_permission) flush_needed = True if flush_needed: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def library_is_public(self, library, contents=False): if contents: @@ -1104,8 +1091,7 @@ def make_library_public(self, library, contents=False): self.sa_session.delete(lp) flush_needed = True if flush_needed: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def folder_is_public(self, folder): for sub_folder in folder.folders: @@ -1216,8 +1202,7 @@ def make_dataset_public(self, dataset): self.sa_session.delete(dp) flush_needed = True if flush_needed: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def derive_roles_from_access(self, trans, item_id, cntrller, library=False, **kwd): # Check the access permission on a dataset. If library is true, item_id refers to a library. If library @@ -1344,8 +1329,7 @@ def copy_library_permissions(self, trans, source_library_item, target_library_it if not found_permission_class.filter_by(role_id=private_role.id, action=action.action).first(): lp = found_permission_class(action.action, target_library_item, private_role) self.sa_session.add(lp) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def get_permitted_libraries(self, trans, user, actions): """ @@ -1749,8 +1733,7 @@ def set_dataset_permissions(self, hda, user, site): else: hdadaa = HistoryDatasetAssociationDisplayAtAuthorization(hda=hda, user=user, site=site) self.sa_session.add(hdadaa) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def _walk_action_roles(permissions, query_action): diff --git a/lib/galaxy/model/store/__init__.py b/lib/galaxy/model/store/__init__.py index c7e7637972d6..a8b515cc5c29 100644 --- a/lib/galaxy/model/store/__init__.py +++ b/lib/galaxy/model/store/__init__.py @@ -62,10 +62,7 @@ ProvidesFileSourcesUserContext, ) from galaxy.files.uris import stream_url_to_file -from galaxy.model.base import ( - ensure_object_added_to_session, - transaction, -) +from galaxy.model.base import ensure_object_added_to_session from galaxy.model.mapping import GalaxyModelMapping from galaxy.model.metadata import MetadataCollection from galaxy.model.orm.util import ( @@ -777,8 +774,7 @@ def import_folder(folder_attrs, root_folder=None): ld.library_dataset_dataset_association = ldda self._session_add(ld) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return library_folder libraries_attrs = self.library_properties() @@ -1330,8 +1326,7 @@ def _session_add(self, obj: model.RepresentById) -> None: self.sa_session.add(obj) def _flush(self) -> None: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def _copied_from_object_key( diff --git a/lib/galaxy/model/tags.py b/lib/galaxy/model/tags.py index bffb0de77794..577fbc5b048d 100644 --- a/lib/galaxy/model/tags.py +++ b/lib/galaxy/model/tags.py @@ -15,7 +15,6 @@ import galaxy.model from galaxy.exceptions import ItemOwnershipException -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.util import ( strip_control_characters, @@ -93,8 +92,7 @@ def set_tags_from_list( new_tags_str = ",".join(new_tags_list) self.apply_item_tags(user, item, unicodify(new_tags_str, "utf-8"), flush=flush) if flush: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() item.update() return item.tags @@ -247,8 +245,7 @@ def apply_item_tag( item_tag_assoc.user_value = value item_tag_assoc.value = lc_value if flush: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return item_tag_assoc def apply_item_tags( @@ -336,8 +333,7 @@ def _create_tag_instance(self, tag_name): with Session() as separate_session: separate_session.add(tag) try: - with transaction(separate_session): - separate_session.commit() + separate_session.commit() except IntegrityError: # tag already exists, get from database separate_session.rollback() From dd221af125cc0c3b379e931a8467cdea3b65aa9c Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 16:25:34 -0500 Subject: [PATCH 12/39] Remove transaction helper from galaxy.tools --- lib/galaxy/tools/__init__.py | 22 +++++---------- lib/galaxy/tools/actions/__init__.py | 10 ++----- lib/galaxy/tools/actions/data_manager.py | 4 +-- lib/galaxy/tools/actions/history_imp_exp.py | 10 ++----- lib/galaxy/tools/actions/metadata.py | 7 ++--- lib/galaxy/tools/actions/upload.py | 4 +-- lib/galaxy/tools/actions/upload_common.py | 31 +++++++-------------- lib/galaxy/tools/execute.py | 13 +++------ lib/galaxy/tools/imp_exp/__init__.py | 7 ++--- 9 files changed, 33 insertions(+), 75 deletions(-) diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index d6531d0846f3..ef1bfad14054 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -50,7 +50,6 @@ Job, StoredWorkflow, ) -from galaxy.model.base import transaction from galaxy.model.dataset_collections.matching import MatchingCollections from galaxy.tool_shed.util.repository_util import get_installed_repository from galaxy.tool_shed.util.shed_util_common import set_image_paths @@ -423,8 +422,7 @@ def reset_tags(self): f"removing all tool tag associations ({str(self.sa_session.scalar(select(func.count(self.app.model.ToolTagAssociation.id))))})" ) self.sa_session.execute(delete(self.app.model.ToolTagAssociation)) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def handle_tags(self, tool_id, tool_definition_source): elem = tool_definition_source @@ -438,12 +436,10 @@ def handle_tags(self, tool_id, tool_definition_source): if not tag: tag = self.app.model.Tag(name=tag_name) self.sa_session.add(tag) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() tta = self.app.model.ToolTagAssociation(tool_id=tool_id, tag_id=tag.id) self.sa_session.add(tta) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() else: for tagged_tool in tag.tagged_tools: if tagged_tool.tool_id == tool_id: @@ -451,8 +447,7 @@ def handle_tags(self, tool_id, tool_definition_source): else: tta = self.app.model.ToolTagAssociation(tool_id=tool_id, tag_id=tag.id) self.sa_session.add(tta) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() class ToolBox(AbstractToolBox): @@ -3144,8 +3139,7 @@ def exec_after_process(self, app, inp_data, out_data, param_dict, job, final_job if not metadata_set_successfully: dataset.state = model.DatasetInstance.states.FAILED_METADATA self.sa_session.add(dataset) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return # If setting external metadata has failed, how can we inform the # user? For now, we'll leave the default metadata and set the state @@ -3164,8 +3158,7 @@ def exec_after_process(self, app, inp_data, out_data, param_dict, job, final_job except Exception: log.exception("Exception occured while setting dataset peek") self.sa_session.add(dataset) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def job_failed(self, job_wrapper, message, exception=False): job = job_wrapper.sa_session.get(Job, job_wrapper.job_id) @@ -3263,8 +3256,7 @@ def _create_data_manager_history(user): history = trans.app.model.History(name="Data Manager History (automatically created)", user=user) data_manager_association = trans.app.model.DataManagerHistoryAssociation(user=user, history=history) trans.sa_session.add_all((history, data_manager_association)) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return history user = trans.user diff --git a/lib/galaxy/tools/actions/__init__.py b/lib/galaxy/tools/actions/__init__.py index fd5f97686fba..fd5812cd5ab3 100644 --- a/lib/galaxy/tools/actions/__init__.py +++ b/lib/galaxy/tools/actions/__init__.py @@ -34,7 +34,6 @@ LibraryDatasetDatasetAssociation, WorkflowRequestInputParameter, ) -from galaxy.model.base import transaction from galaxy.model.dataset_collections.builder import CollectionBuilder from galaxy.model.dataset_collections.matching import MatchingCollections from galaxy.model.none_like import NoneDataset @@ -755,15 +754,13 @@ def handle_output(name, output, hidden=None): job.set_state(app.model.Job.states.OK) job.info = f"Redirected to: {redirect_url}" trans.sa_session.add(job) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() trans.response.send_redirect(redirect_url) else: if flush_job: # Set HID and add to history. job_flush_timer = ExecutionTimer() - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() log.info(f"Flushed transaction for job {job.log_str()} {job_flush_timer}") return job, out_data, history @@ -811,8 +808,7 @@ def _remap_job_on_rerun( session = trans.sa_session() try: session.expire_on_commit = False - with transaction(session): - session.commit() + session.commit() finally: session.expire_on_commit = True try: diff --git a/lib/galaxy/tools/actions/data_manager.py b/lib/galaxy/tools/actions/data_manager.py index d8786ad5a921..0bed347af3bd 100644 --- a/lib/galaxy/tools/actions/data_manager.py +++ b/lib/galaxy/tools/actions/data_manager.py @@ -5,7 +5,6 @@ History, Job, ) -from galaxy.model.base import transaction from galaxy.model.dataset_collections.matching import MatchingCollections from galaxy.tools._types import ToolStateJobInstancePopulatedT from galaxy.tools.execute import ( @@ -67,8 +66,7 @@ def execute( if isinstance(rval, tuple) and len(rval) >= 2 and isinstance(rval[0], trans.app.model.Job): assoc = trans.app.model.DataManagerJobAssociation(job=rval[0], data_manager_id=tool.data_manager_id) trans.sa_session.add(assoc) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() else: log.error(f"Got bad return value from DefaultToolAction.execute(): {rval}") return rval diff --git a/lib/galaxy/tools/actions/history_imp_exp.py b/lib/galaxy/tools/actions/history_imp_exp.py index de502f3a11d7..83b5848c8e01 100644 --- a/lib/galaxy/tools/actions/history_imp_exp.py +++ b/lib/galaxy/tools/actions/history_imp_exp.py @@ -9,7 +9,6 @@ History, Job, ) -from galaxy.model.base import transaction from galaxy.model.dataset_collections.matching import MatchingCollections from galaxy.tools._types import ToolStateJobInstancePopulatedT from galaxy.tools.actions import ( @@ -81,8 +80,7 @@ def execute( job.states.WAITING ) # we need to set job state to something other than NEW, or else when tracking jobs in db it will be picked up before we have added input / output parameters trans.sa_session.add(job) - with transaction(trans.sa_session): # ensure job.id are available - trans.sa_session.commit() + trans.sa_session.commit() # ensure job.id are available # # Setup job and job wrapper. @@ -183,8 +181,7 @@ def execute( # dynamic objectstore assignment, etc..) but it is arguably less bad than # creating a dataset (like above for dataset export case). # ensure job.id is available - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() job_directory = create_working_directory_for_job(trans.app.object_store, job) store_directory = os.path.join(job_directory, "working", "_object_export") os.makedirs(store_directory) @@ -222,8 +219,7 @@ def execute( for name, value in tool.params_to_strings(incoming, trans.app).items(): job.add_parameter(name, value) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() job_wrapper = JobExportHistoryArchiveWrapper(trans.app, job.id) job_wrapper.setup_job( diff --git a/lib/galaxy/tools/actions/metadata.py b/lib/galaxy/tools/actions/metadata.py index 2b46c6060ccd..08b08ba62e27 100644 --- a/lib/galaxy/tools/actions/metadata.py +++ b/lib/galaxy/tools/actions/metadata.py @@ -14,7 +14,6 @@ Job, User, ) -from galaxy.model.base import transaction from galaxy.model.dataset_collections.matching import MatchingCollections from galaxy.tools._types import ToolStateJobInstancePopulatedT from galaxy.tools.execute import ( @@ -155,8 +154,7 @@ def execute_via_app( job.states.WAITING ) # we need to set job state to something other than NEW, or else when tracking jobs in db it will be picked up before we have added input / output parameters sa_session.add(job) - with transaction(sa_session): # ensure job.id is available - sa_session.commit() + sa_session.commit() # ensure job.id is available # add parameters to job_parameter table # Store original dataset state, so we can restore it. A separate table might be better (no chance of 'losing' the original state)? @@ -202,8 +200,7 @@ def execute_via_app( # i.e. if state was set to 'running' the set metadata job would never run, as it would wait for input (the dataset to set metadata on) to be in a ready state dataset.state = dataset.states.SETTING_METADATA job.state = start_job_state # job inputs have been configured, restore initial job state - with transaction(sa_session): - sa_session.commit() + sa_session.commit() # clear e.g. converted files dataset.datatype.before_setting_metadata(dataset) diff --git a/lib/galaxy/tools/actions/upload.py b/lib/galaxy/tools/actions/upload.py index c758c96b2ae7..1b496e98643a 100644 --- a/lib/galaxy/tools/actions/upload.py +++ b/lib/galaxy/tools/actions/upload.py @@ -8,7 +8,6 @@ History, Job, ) -from galaxy.model.base import transaction from galaxy.model.dataset_collections.matching import MatchingCollections from galaxy.model.dataset_collections.structure import UninitializedTree from galaxy.tools._types import ToolStateJobInstancePopulatedT @@ -188,6 +187,5 @@ def _precreate_fetched_collection_instance(trans, history, target, outputs): ) outputs.append(hdca) # Following flushed needed for an ID. - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() target["destination"]["object_id"] = hdca.id diff --git a/lib/galaxy/tools/actions/upload_common.py b/lib/galaxy/tools/actions/upload_common.py index 924bdc64a3b5..2c34a76204a0 100644 --- a/lib/galaxy/tools/actions/upload_common.py +++ b/lib/galaxy/tools/actions/upload_common.py @@ -30,7 +30,6 @@ LibraryFolder, Role, ) -from galaxy.model.base import transaction from galaxy.util import is_url from galaxy.util.path import external_chown @@ -143,8 +142,7 @@ def __new_history_upload(trans, uploaded_dataset, history=None, state=None): history.add_dataset(hda, genome_build=uploaded_dataset.dbkey, quota=False) permissions = trans.app.security_agent.history_get_default_permissions(history) trans.app.security_agent.set_all_dataset_permissions(hda.dataset, permissions, new=True, flush=False) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return hda @@ -169,8 +167,7 @@ def __new_library_upload(trans, cntrller, uploaded_dataset, library_bunch, tag_h new_folder.genome_build = trans.app.genome_builds.default_value folder.add_folder(new_folder) trans.sa_session.add(new_folder) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() trans.app.security_agent.copy_library_permissions(trans, folder, new_folder) folder = new_folder if library_bunch.replace_dataset: @@ -178,8 +175,7 @@ def __new_library_upload(trans, cntrller, uploaded_dataset, library_bunch, tag_h else: ld = trans.app.model.LibraryDataset(folder=folder, name=uploaded_dataset.name) trans.sa_session.add(ld) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() trans.app.security_agent.copy_library_permissions(trans, folder, ld) ldda = trans.app.model.LibraryDatasetDatasetAssociation( name=uploaded_dataset.name, @@ -205,8 +201,7 @@ def __new_library_upload(trans, cntrller, uploaded_dataset, library_bunch, tag_h else: ldda.state = ldda.states.QUEUED ldda.message = library_bunch.message - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Permissions must be the same on the LibraryDatasetDatasetAssociation and the associated LibraryDataset trans.app.security_agent.copy_library_permissions(trans, ld, ldda) if library_bunch.replace_dataset: @@ -221,12 +216,10 @@ def __new_library_upload(trans, cntrller, uploaded_dataset, library_bunch, tag_h ) folder.add_library_dataset(ld, genome_build=uploaded_dataset.dbkey) trans.sa_session.add(folder) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() ld.library_dataset_dataset_association_id = ldda.id trans.sa_session.add(ld) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Handle template included in the upload form, if any. If the upload is not asynchronous ( e.g., URL paste ), # then the template and contents will be included in the library_bunch at this point. If the upload is # asynchronous ( e.g., uploading a file ), then the template and contents will be included in the library_bunch @@ -238,8 +231,7 @@ def __new_library_upload(trans, cntrller, uploaded_dataset, library_bunch, tag_h # Create a new FormValues object, using the template we previously retrieved form_values = trans.app.model.FormValues(library_bunch.template, library_bunch.template_field_contents) trans.sa_session.add(form_values) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Create a new info_association between the current ldda and form_values # TODO: Currently info_associations at the ldda level are not inheritable to the associated LibraryDataset, # we need to figure out if this is optimal @@ -247,8 +239,7 @@ def __new_library_upload(trans, cntrller, uploaded_dataset, library_bunch, tag_h ldda, library_bunch.template, form_values ) trans.sa_session.add(info_association) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # If roles were selected upon upload, restrict access to the Dataset to those roles if library_bunch.roles: for role in library_bunch.roles: @@ -256,8 +247,7 @@ def __new_library_upload(trans, cntrller, uploaded_dataset, library_bunch, tag_h trans.app.security_agent.permitted_actions.DATASET_ACCESS.action, ldda.dataset, role ) trans.sa_session.add(dp) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return ldda @@ -314,8 +304,7 @@ def create_paramfile(trans, uploaded_datasets): for meta_name, meta_value in uploaded_dataset.metadata.items(): setattr(data.metadata, meta_name, meta_value) trans.sa_session.add(data) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() params = dict( file_type=uploaded_dataset.file_type, dataset_id=data.dataset.id, diff --git a/lib/galaxy/tools/execute.py b/lib/galaxy/tools/execute.py index 775caa4ce8ab..f837902e51b8 100644 --- a/lib/galaxy/tools/execute.py +++ b/lib/galaxy/tools/execute.py @@ -25,7 +25,6 @@ from galaxy import model from galaxy.exceptions import ToolInputsNotOKException -from galaxy.model.base import transaction from galaxy.model.dataset_collections.matching import MatchingCollections from galaxy.model.dataset_collections.structure import ( get_structure, @@ -197,8 +196,7 @@ def execute_single_job(execution_slice: "ExecutionSlice", completed_job: Optiona if execution_slice: history.add_pending_items() # Make sure collections, implicit jobs etc are flushed even if there are no precreated output datasets - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() tool_id = tool.id for job2 in execution_tracker.successful_jobs: @@ -231,8 +229,7 @@ def execute_single_job(execution_slice: "ExecutionSlice", completed_job: Optiona continue tool.app.job_manager.enqueue(job2, tool=tool, flush=False) trans.log_event(f"Added job to the job queue, id: {str(job2.id)}", tool_id=tool_id) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if has_remaining_jobs: raise PartialJobExecution(execution_tracker) @@ -483,8 +480,7 @@ def replace_optional_runtime_values(path, key, value): trans.sa_session.add(collection_instance) # Needed to flush the association created just above with # job.add_output_dataset_collection. - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() self.implicit_collections = collection_instances @property @@ -554,8 +550,7 @@ def finalize_dataset_collections(self, trans): trans.sa_session.add(implicit_collection.collection) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() @property def implicit_inputs(self): diff --git a/lib/galaxy/tools/imp_exp/__init__.py b/lib/galaxy/tools/imp_exp/__init__.py index a1338d8c453b..675a4cee00a7 100644 --- a/lib/galaxy/tools/imp_exp/__init__.py +++ b/lib/galaxy/tools/imp_exp/__init__.py @@ -8,7 +8,6 @@ from galaxy import model from galaxy.model import store -from galaxy.model.base import transaction from galaxy.schema.tasks import SetupHistoryExportJob from galaxy.util.path import external_chown @@ -76,8 +75,7 @@ def cleanup_after_job(self): job = jiha.job with model_store.target_history(default_history=job.history) as new_history: jiha.history = new_history - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() model_store.perform_import(new_history, job=job, new_history=True) # Cleanup. if os.path.exists(archive_dir): @@ -85,8 +83,7 @@ def cleanup_after_job(self): except Exception as e: jiha.job.tool_stderr += f"Error cleaning up history import job: {e}" - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() raise return new_history From cf4f7f9af6baa4a4bfb83bcdbe562efa322faf7c Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 16:30:54 -0500 Subject: [PATCH 13/39] Remove transaction helper from galaxy.job_execution --- lib/galaxy/job_execution/output_collect.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/galaxy/job_execution/output_collect.py b/lib/galaxy/job_execution/output_collect.py index 8e37864767d0..ecd24994d4d3 100644 --- a/lib/galaxy/job_execution/output_collect.py +++ b/lib/galaxy/job_execution/output_collect.py @@ -24,7 +24,6 @@ JobToOutputDatasetAssociation, LibraryDatasetDatasetAssociation, ) -from galaxy.model.base import transaction from galaxy.model.dataset_collections import builder from galaxy.model.dataset_collections.structure import UninitializedTree from galaxy.model.dataset_collections.type_description import COLLECTION_TYPE_DESCRIPTION_FACTORY @@ -302,8 +301,7 @@ def persist_object(self, obj): self.sa_session.add(obj) def flush(self): - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def get_library_folder(self, destination): app = self.app @@ -343,8 +341,7 @@ def add_library_dataset_to_folder(self, library_folder, ld): trans = self.work_context trans.app.security_agent.copy_library_permissions(trans, library_folder, ld) trans.sa_session.add(ld) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Permissions must be the same on the LibraryDatasetDatasetAssociation and the associated LibraryDataset trans.app.security_agent.copy_library_permissions(trans, ld, ldda) @@ -354,12 +351,10 @@ def add_library_dataset_to_folder(self, library_folder, ld): ) library_folder.add_library_dataset(ld, genome_build=ldda.dbkey) trans.sa_session.add(library_folder) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() trans.sa_session.add(ld) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def add_datasets_to_history(self, datasets, for_output_dataset=None): sa_session = self.sa_session From 87bb447bcf958ce820b31c7c8d8dcb67d4fe96f5 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 16:47:41 -0500 Subject: [PATCH 14/39] Remove transaction helper from galaxy.managers --- lib/galaxy/managers/annotatable.py | 7 ++----- lib/galaxy/managers/api_keys.py | 7 ++----- lib/galaxy/managers/base.py | 17 +++++----------- lib/galaxy/managers/chat.py | 7 ++----- lib/galaxy/managers/collections.py | 23 +++++++++------------- lib/galaxy/managers/context.py | 11 +++-------- lib/galaxy/managers/datasets.py | 26 +++++++++---------------- lib/galaxy/managers/export_tracker.py | 7 ++----- lib/galaxy/managers/folders.py | 10 +++------- lib/galaxy/managers/forms.py | 7 ++----- lib/galaxy/managers/group_roles.py | 7 ++----- lib/galaxy/managers/group_users.py | 7 ++----- lib/galaxy/managers/groups.py | 10 +++------- lib/galaxy/managers/hdas.py | 19 ++++++------------ lib/galaxy/managers/histories.py | 10 +++------- lib/galaxy/managers/interactivetool.py | 16 +++++---------- lib/galaxy/managers/item_tags.py | 7 ++----- lib/galaxy/managers/jobs.py | 4 +--- lib/galaxy/managers/landing.py | 4 +--- lib/galaxy/managers/libraries.py | 10 +++------- lib/galaxy/managers/library_datasets.py | 4 +--- lib/galaxy/managers/model_stores.py | 4 +--- lib/galaxy/managers/notification.py | 25 ++++++++---------------- lib/galaxy/managers/pages.py | 7 ++----- lib/galaxy/managers/quotas.py | 25 ++++++++---------------- lib/galaxy/managers/ratable.py | 4 +--- lib/galaxy/managers/rbac_secured.py | 10 +++------- lib/galaxy/managers/roles.py | 13 ++++--------- lib/galaxy/managers/sharable.py | 16 +++++---------- lib/galaxy/managers/tags.py | 4 +--- lib/galaxy/managers/users.py | 22 +++++++-------------- lib/galaxy/managers/workflows.py | 20 ++++++------------- 32 files changed, 114 insertions(+), 256 deletions(-) diff --git a/lib/galaxy/managers/annotatable.py b/lib/galaxy/managers/annotatable.py index 4a0ad04ab2ea..e8b62b5d600e 100644 --- a/lib/galaxy/managers/annotatable.py +++ b/lib/galaxy/managers/annotatable.py @@ -11,7 +11,6 @@ from sqlalchemy.orm import scoped_session -from galaxy.model.base import transaction from .base import ( Deserializer, FunctionFilterParsersType, @@ -64,8 +63,7 @@ def annotate(self, item, annotation, user=None, flush=True): annotation_obj = item.add_item_annotation(self.session(), user, item, annotation) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return annotation_obj def _user_annotation(self, item, user): @@ -75,8 +73,7 @@ def _delete_annotation(self, item, user, flush=True): returned = item.delete_item_annotation(self.session(), user, item) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return returned diff --git a/lib/galaxy/managers/api_keys.py b/lib/galaxy/managers/api_keys.py index e306049259cb..0f117715a6b9 100644 --- a/lib/galaxy/managers/api_keys.py +++ b/lib/galaxy/managers/api_keys.py @@ -5,7 +5,6 @@ ) from typing_extensions import Protocol -from galaxy.model.base import transaction from galaxy.structured_app import BasicSharedApp @@ -29,8 +28,7 @@ def create_api_key(self, user: IsUserModel): new_key.user_id = user.id new_key.key = guid self.session.add(new_key) - with transaction(self.session): - self.session.commit() + self.session.commit() return new_key def get_or_create_api_key(self, user: IsUserModel) -> str: @@ -46,8 +44,7 @@ def delete_api_key(self, user: IsUserModel) -> None: # Before it was possible to create multiple API keys for the same user although they were not considered valid # So all non-deleted keys are marked as deleted for backward compatibility self._mark_all_api_keys_as_deleted(user.id) - with transaction(self.session): - self.session.commit() + self.session.commit() def _mark_all_api_keys_as_deleted(self, user_id: int): APIKeys = self.app.model.APIKeys diff --git a/lib/galaxy/managers/base.py b/lib/galaxy/managers/base.py index 135616fbed5a..396f8d12a898 100644 --- a/lib/galaxy/managers/base.py +++ b/lib/galaxy/managers/base.py @@ -55,10 +55,7 @@ model, ) from galaxy.model import tool_shed_install -from galaxy.model.base import ( - check_database_connection, - transaction, -) +from galaxy.model.base import check_database_connection from galaxy.schema import ValueFilterQueryParams from galaxy.schema.storage_cleaner import ( CleanableItemsSummary, @@ -223,8 +220,7 @@ def _session_setattr(self, item: model.Base, attr: str, val: Any, flush: bool = self.session().add(item) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return item # .... query foundation wrapper @@ -493,8 +489,7 @@ def create(self, flush: bool = True, *args: Any, **kwargs: Any) -> U: self.session().add(item) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return item def copy(self, item, **kwargs) -> U: @@ -515,8 +510,7 @@ def update(self, item: U, new_values: Dict[str, Any], flush: bool = True, **kwar session = self.session() session.add(item) if flush: - with transaction(session): - session.commit() + session.commit() return item def associate(self, associate_with, item, foreign_key_name=None): @@ -932,8 +926,7 @@ def deserialize(self, item, data, flush=True, **context): # TODO:?? add and flush here or in manager? if flush and len(new_dict): sa_session.add(item) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() return new_dict diff --git a/lib/galaxy/managers/chat.py b/lib/galaxy/managers/chat.py index ecf651602684..377837afc1ee 100644 --- a/lib/galaxy/managers/chat.py +++ b/lib/galaxy/managers/chat.py @@ -16,7 +16,6 @@ ) from galaxy.managers.context import ProvidesUserContext from galaxy.model import ChatExchange -from galaxy.model.base import transaction from galaxy.util import unicodify @@ -38,8 +37,7 @@ def create(self, trans: ProvidesUserContext, job_id: int, message: str) -> ChatE """ chat_exchange = ChatExchange(user=trans.user, job_id=job_id, message=message) trans.sa_session.add(chat_exchange) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return chat_exchange def get(self, trans: ProvidesUserContext, job_id: int) -> Union[ChatExchange, None]: @@ -93,7 +91,6 @@ def set_feedback_for_job(self, trans: ProvidesUserContext, job_id: int, feedback # There is only one message in an exchange currently, so we can set the feedback on the first message chat_exchange.messages[0].feedback = feedback - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return chat_exchange diff --git a/lib/galaxy/managers/collections.py b/lib/galaxy/managers/collections.py index fae6d0563347..ee3a98c3c168 100644 --- a/lib/galaxy/managers/collections.py +++ b/lib/galaxy/managers/collections.py @@ -34,7 +34,6 @@ from galaxy.managers.hdcas import write_dataset_collection from galaxy.managers.histories import HistoryManager from galaxy.managers.lddas import LDDAManager -from galaxy.model.base import transaction from galaxy.model.dataset_collections import builder from galaxy.model.dataset_collections.matching import MatchingCollections from galaxy.model.dataset_collections.registry import DATASET_COLLECTION_TYPES_REGISTRY @@ -430,8 +429,7 @@ def delete(self, trans: ProvidesHistoryContext, instance_type, id, recursive=Fal if purge and not dataset.purged: async_result = self.hda_manager.purge(dataset, user=trans.user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return async_result def update(self, trans: ProvidesHistoryContext, instance_type, id, payload): @@ -474,8 +472,7 @@ def copy( new_hdca.copy_tags_from(target_user=trans.get_user(), source=source_hdca) if not copy_elements: parent.add_dataset_collection(new_hdca) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return new_hdca def _set_from_dict(self, trans: ProvidesUserContext, dataset_collection_instance, new_data): @@ -501,8 +498,7 @@ def _set_from_dict(self, trans: ProvidesUserContext, dataset_collection_instance ) if changed.keys(): - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # set client tag field response after the flush if new_tags is not None: @@ -530,11 +526,10 @@ def history_dataset_collections(self, history, query): return collections def __persist(self, dataset_collection_instance, flush=True): - context = self.model.context - context.add(dataset_collection_instance) + session = self.model.session + session.add(dataset_collection_instance) if flush: - with transaction(context): - context.commit() + session.commit() return dataset_collection_instance def __recursively_create_collections_for_identifiers( @@ -615,9 +610,9 @@ def __load_element(self, trans, element_identifier, hide_source_items, copy_elem if "__object__" in element_identifier: the_object = element_identifier["__object__"] if the_object is not None and the_object.id: - context = self.model.context - if the_object not in context: - the_object = context.get(type(the_object), the_object.id) + session = self.model.session + if the_object not in session: + the_object = session.get(type(the_object), the_object.id) return the_object # dataset_identifier is dict {src=hda|ldda|hdca|new_collection, id=} diff --git a/lib/galaxy/managers/context.py b/lib/galaxy/managers/context.py index 89a9c32c8902..eef80a5fe675 100644 --- a/lib/galaxy/managers/context.py +++ b/lib/galaxy/managers/context.py @@ -62,10 +62,7 @@ Role, User, ) -from galaxy.model.base import ( - ModelMapping, - transaction, -) +from galaxy.model.base import ModelMapping from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.model.tags import GalaxyTagHandlerSession from galaxy.schema.tasks import RequestUser @@ -124,8 +121,7 @@ def log_action(self, user=None, action=None, context=None, params=None): except Exception: action.session_id = None self.sa_session.add(action) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def log_event(self, message, tool_id=None, **kwargs): """ @@ -156,8 +152,7 @@ def log_event(self, message, tool_id=None, **kwargs): except Exception: event.session_id = None self.sa_session.add(event) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() @property def sa_session(self) -> galaxy_scoped_session: diff --git a/lib/galaxy/managers/datasets.py b/lib/galaxy/managers/datasets.py index d82cd463cf4f..d990ee321eb6 100644 --- a/lib/galaxy/managers/datasets.py +++ b/lib/galaxy/managers/datasets.py @@ -34,7 +34,6 @@ DatasetInstance, HistoryDatasetAssociation, ) -from galaxy.model.base import transaction from galaxy.schema.tasks import ( ComputeDatasetHashTaskRequest, PurgeDatasetsTaskRequest, @@ -82,8 +81,7 @@ def purge(self, item, flush=True, **kwargs): self.session().add(item) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return item def purge_datasets(self, request: PurgeDatasetsTaskRequest): @@ -154,10 +152,9 @@ def update_object_store_id(self, trans, dataset, object_store_id: str): if old_label != new_label: self.quota_agent.relabel_quota_for_dataset(dataset, old_label, new_label) sa_session = self.session() - with transaction(sa_session): - dataset.object_store_id = new_object_store_id - sa_session.add(dataset) - sa_session.commit() + dataset.object_store_id = new_object_store_id + sa_session.add(dataset) + sa_session.commit() def compute_hash(self, request: ComputeDatasetHashTaskRequest): dataset = self.by_id(request.dataset_id) @@ -185,8 +182,7 @@ def compute_hash(self, request: ComputeDatasetHashTaskRequest): hash = get_dataset_hash(sa_session, dataset.id, hash_function, extra_files_path) if hash is None: sa_session.add(dataset_hash) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() else: old_hash_value = hash.hash_value if old_hash_value != calculated_hash_value: @@ -425,8 +421,7 @@ def stop_creating_job(self, dataset_assoc: U, flush=False): self.app.job_manager.stop(job) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return True return False @@ -537,8 +532,7 @@ def detect_datatype(self, trans, dataset_assoc: U): path = dataset_assoc.dataset.get_file_name() datatype = sniff.guess_ext(path, self.app.datatypes_registry.sniff_order) self.app.datatypes_registry.change_datatype(dataset_assoc, datatype) - with transaction(session): - session.commit() + session.commit() self.set_metadata(trans, dataset_assoc) def set_metadata(self, trans, dataset_assoc: U, overwrite: bool = False, validate: bool = True) -> None: @@ -594,8 +588,7 @@ def update_permissions(self, trans, dataset_assoc: U, **kwd): self.app.security_agent.permitted_actions.DATASET_ACCESS.action, dataset, private_role ) trans.sa_session.add(dp) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if not self.app.security_agent.dataset_is_private_to_user(trans, dataset): # Check again and inform the user if dataset is not private. raise exceptions.InternalServerError("An error occurred and the dataset is NOT private.") @@ -877,8 +870,7 @@ def deserialize_datatype(self, item, key, val, **context): ) item.change_datatype(val) sa_session = self.app.model.context - with transaction(sa_session): - sa_session.commit() + sa_session.commit() trans = context.get("trans") assert ( trans diff --git a/lib/galaxy/managers/export_tracker.py b/lib/galaxy/managers/export_tracker.py index 1f70d9e84265..73853073010b 100644 --- a/lib/galaxy/managers/export_tracker.py +++ b/lib/galaxy/managers/export_tracker.py @@ -13,7 +13,6 @@ from galaxy.exceptions import ObjectNotFound from galaxy.model import StoreExportAssociation -from galaxy.model.base import transaction from galaxy.schema.schema import ExportObjectType from galaxy.structured_app import MinimalManagerApp @@ -34,8 +33,7 @@ def session(self) -> scoped_session: def create_export_association(self, object_id: int, object_type: ExportObjectType) -> StoreExportAssociation: export_association = StoreExportAssociation(object_id=object_id, object_type=object_type) self.session.add(export_association) - with transaction(self.session): - self.session.commit() + self.session.commit() return export_association def set_export_association_metadata(self, export_association_id: int, export_metadata: BaseModel): @@ -45,8 +43,7 @@ def set_export_association_metadata(self, export_association_id: int, export_met except NoResultFound: raise ObjectNotFound("Cannot set export metadata. Reason: Export association not found") export_association.export_metadata = export_metadata.model_dump_json() # type:ignore[assignment] - with transaction(self.session): - self.session.commit() + self.session.commit() def get_export_association(self, export_association_id: int) -> StoreExportAssociation: try: diff --git a/lib/galaxy/managers/folders.py b/lib/galaxy/managers/folders.py index ff13b16083b1..9f1577c64980 100644 --- a/lib/galaxy/managers/folders.py +++ b/lib/galaxy/managers/folders.py @@ -48,7 +48,6 @@ LibraryFolder, LibraryFolderPermissions, ) -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.schema.schema import LibraryFolderContentsIndexQueryPayload from galaxy.security import RBACAgent @@ -220,8 +219,7 @@ def create(self, trans, parent_folder_id, new_folder_name, new_folder_descriptio new_folder.genome_build = trans.app.genome_builds.default_value parent_folder.add_folder(new_folder) trans.sa_session.add(new_folder) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # New folders default to having the same permissions as their parent folder trans.app.security_agent.copy_library_permissions(trans, parent_folder, new_folder) return new_folder @@ -255,8 +253,7 @@ def update(self, trans, folder, name=None, description=None): changed = True if changed: trans.sa_session.add(folder) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return folder def delete(self, trans, folder, undelete=False): @@ -280,8 +277,7 @@ def delete(self, trans, folder, undelete=False): else: folder.deleted = True trans.sa_session.add(folder) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return folder def get_current_roles(self, trans, folder): diff --git a/lib/galaxy/managers/forms.py b/lib/galaxy/managers/forms.py index fdbbd4985e7c..d8da000445d5 100644 --- a/lib/galaxy/managers/forms.py +++ b/lib/galaxy/managers/forms.py @@ -15,7 +15,6 @@ FormDefinition, FormDefinitionCurrent, ) -from galaxy.model.base import transaction from galaxy.util import unicodify @@ -73,13 +72,11 @@ def get(self, trans: ProvidesUserContext, form_id: int) -> FormDefinitionCurrent def delete(self, trans: ProvidesUserContext, form: FormDefinitionCurrent) -> FormDefinitionCurrent: form.deleted = True trans.sa_session.add(form) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return form def undelete(self, trans: ProvidesUserContext, form: FormDefinitionCurrent) -> FormDefinitionCurrent: form.deleted = False trans.sa_session.add(form) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return form diff --git a/lib/galaxy/managers/group_roles.py b/lib/galaxy/managers/group_roles.py index c942bbe7431a..e48fa3001ac1 100644 --- a/lib/galaxy/managers/group_roles.py +++ b/lib/galaxy/managers/group_roles.py @@ -10,7 +10,6 @@ from galaxy.exceptions import ObjectNotFound from galaxy.managers.context import ProvidesAppContext from galaxy.model import GroupRoleAssociation -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.structured_app import MinimalManagerApp @@ -84,13 +83,11 @@ def _get_group_role( def _add_role_to_group(self, trans: ProvidesAppContext, group: model.Group, role: model.Role): gra = model.GroupRoleAssociation(group, role) trans.sa_session.add(gra) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def _remove_role_from_group(self, trans: ProvidesAppContext, group_role: model.GroupRoleAssociation): trans.sa_session.delete(group_role) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def get_group_role(session: galaxy_scoped_session, group, role) -> Optional[GroupRoleAssociation]: diff --git a/lib/galaxy/managers/group_users.py b/lib/galaxy/managers/group_users.py index 6bcd088fcc3f..8b4d0650a1ad 100644 --- a/lib/galaxy/managers/group_users.py +++ b/lib/galaxy/managers/group_users.py @@ -13,7 +13,6 @@ User, UserGroupAssociation, ) -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.structured_app import MinimalManagerApp @@ -87,13 +86,11 @@ def _get_group_user( def _add_user_to_group(self, trans: ProvidesAppContext, group: model.Group, user: model.User): gra = model.UserGroupAssociation(user, group) trans.sa_session.add(gra) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def _remove_user_from_group(self, trans: ProvidesAppContext, group_user: model.UserGroupAssociation): trans.sa_session.delete(group_user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def get_group_user(session: galaxy_scoped_session, user, group) -> Optional[UserGroupAssociation]: diff --git a/lib/galaxy/managers/groups.py b/lib/galaxy/managers/groups.py index e0d6cd177731..e204a17a89d9 100644 --- a/lib/galaxy/managers/groups.py +++ b/lib/galaxy/managers/groups.py @@ -12,7 +12,6 @@ ) from galaxy.managers.context import ProvidesAppContext from galaxy.model import Group -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.schema.fields import Security from galaxy.schema.groups import ( @@ -99,8 +98,7 @@ def delete(self, trans: ProvidesAppContext, group_id: int): group = self._get_group(trans.sa_session, group_id) group.deleted = True trans.sa_session.add(group) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def purge(self, trans: ProvidesAppContext, group_id: int): sa_session = trans.sa_session @@ -117,8 +115,7 @@ def purge(self, trans: ProvidesAppContext, group_id: int): sa_session.delete(gra) # Delete the group sa_session.delete(group) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() def undelete(self, trans: ProvidesAppContext, group_id: int): group = self._get_group(trans.sa_session, group_id) @@ -128,8 +125,7 @@ def undelete(self, trans: ProvidesAppContext, group_id: int): ) group.deleted = False trans.sa_session.add(group) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def _url_for(self, trans, name, **kwargs): return trans.url_builder(name, **kwargs) diff --git a/lib/galaxy/managers/hdas.py b/lib/galaxy/managers/hdas.py index a1103f45ff0f..e2871369589d 100644 --- a/lib/galaxy/managers/hdas.py +++ b/lib/galaxy/managers/hdas.py @@ -51,7 +51,6 @@ JobStateHistory, JobToOutputDatasetAssociation, ) -from galaxy.model.base import transaction from galaxy.model.deferred import materializer_factory from galaxy.model.dereference import dereference_to_model from galaxy.schema.schema import DatasetSourceType @@ -158,8 +157,7 @@ def create( self.session().add(hda) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return hda def materialize(self, request: MaterializeDatasetInstanceTaskRequest, in_place: bool = False) -> bool: @@ -182,8 +180,7 @@ def materialize(self, request: MaterializeDatasetInstanceTaskRequest, in_place: else: new_hda.set_total_size() session = self.session() - with transaction(session): - session.commit() + session.commit() return new_hda.is_ok def copy( @@ -215,8 +212,7 @@ def copy( history.add_pending_items() session = object_session(copy) assert session - with transaction(session): - session.commit() + session.commit() return copy @@ -247,8 +243,7 @@ def _purge(self, hda: HistoryDatasetAssociation, flush: bool = True): # TODO: don't flush above if we're going to re-flush here session = object_session(user) assert session - with transaction(session): - session.commit() + session.commit() # .... states def error_if_uploading(self, hda): @@ -343,8 +338,7 @@ def dereference_input( hda = dereference_to_model(trans.sa_session, trans.user, target_history, data_request) permissions = trans.app.security_agent.history_get_default_permissions(target_history) trans.app.security_agent.set_all_dataset_permissions(hda.dataset, permissions, new=True, flush=False) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return hda @@ -439,8 +433,7 @@ def cleanup_items(self, user: model.User, item_ids: Set[int]) -> StorageItemsCle if success_item_count: session = self.hda_manager.session() - with transaction(session): - session.commit() + session.commit() self._request_full_delete_all(dataset_ids_to_remove, user) diff --git a/lib/galaxy/managers/histories.py b/lib/galaxy/managers/histories.py index 392c36016791..8ccd80b88b27 100644 --- a/lib/galaxy/managers/histories.py +++ b/lib/galaxy/managers/histories.py @@ -56,7 +56,6 @@ HistoryUserShareAssociation, Job, ) -from galaxy.model.base import transaction from galaxy.model.index_filter_util import ( append_user_filter, raw_text_column_filter, @@ -506,8 +505,7 @@ def archive_history(self, history: model.History, archive_export_id: Optional[in """ history.archived = True history.archive_export_id = archive_export_id - with transaction(self.session()): - self.session().commit() + self.session().commit() return history @@ -529,8 +527,7 @@ def restore_archived_history(self, history: model.History, force: bool = False): ) history.archived = False - with transaction(self.session()): - self.session().commit() + self.session().commit() return history @@ -641,8 +638,7 @@ def cleanup_items(self, user: model.User, item_ids: Set[int]) -> StorageItemsCle if success_item_count: session = self.history_manager.session() - with transaction(session): - session.commit() + session.commit() return StorageItemsCleanupResult( total_item_count=len(item_ids), diff --git a/lib/galaxy/managers/interactivetool.py b/lib/galaxy/managers/interactivetool.py index f96fac35d96b..7e59516c6411 100644 --- a/lib/galaxy/managers/interactivetool.py +++ b/lib/galaxy/managers/interactivetool.py @@ -24,7 +24,6 @@ InteractiveToolEntryPoint, Job, ) -from galaxy.model.base import transaction from galaxy.security.idencoding import IdAsLowercaseAlphanumEncodingHelper log = logging.getLogger(__name__) @@ -154,8 +153,7 @@ def create_entry_points(self, job, tool, entry_points=None, flush=True): ) self.sa_session.add(ep) if flush: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def configure_entry_point(self, job, tool_port=None, host=None, port=None, protocol=None): return self.configure_entry_points( @@ -180,8 +178,7 @@ def configure_entry_points(self, job, ports_dict): self.save_entry_point(ep) configured.append(ep) if configured: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return dict(not_configured=not_configured, configured=configured) def save_entry_point(self, entry_point): @@ -249,22 +246,19 @@ def stop(self, trans, entry_point): # This self.job_manager.stop(job) does nothing without changing job.state, manually or e.g. with .mark_deleted() self.job_manager.stop(job) trans.sa_session.add(job) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def remove_entry_points(self, entry_points): if entry_points: for entry_point in entry_points: self.remove_entry_point(entry_point, flush=False) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def remove_entry_point(self, entry_point, flush=True): entry_point.deleted = True self.sa_session.add(entry_point) if flush: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() self.propagator.remove_entry_point(entry_point) def target_if_active(self, trans, entry_point): diff --git a/lib/galaxy/managers/item_tags.py b/lib/galaxy/managers/item_tags.py index bd2064dee9f4..90f43e942b45 100644 --- a/lib/galaxy/managers/item_tags.py +++ b/lib/galaxy/managers/item_tags.py @@ -4,7 +4,6 @@ ) from galaxy.managers import base from galaxy.managers.context import ProvidesAppContext -from galaxy.model.base import transaction from galaxy.schema.fields import DecodedDatabaseIdField from galaxy.schema.item_tags import ItemTagsCreatePayload from galaxy.structured_app import MinimalManagerApp @@ -68,16 +67,14 @@ def _remove_items_tag(self, trans, item_class_name, id, tag_name): user = trans.user tagged_item = self._get_tagged_item(trans, item_class_name, id) deleted = tagged_item and self._tag_handler.remove_item_tag(user, tagged_item, tag_name) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return deleted def _apply_item_tag(self, trans, item_class_name, id, tag_name, tag_value=None): user = trans.user tagged_item = self._get_tagged_item(trans, item_class_name, id) tag_assoc = self._tag_handler.apply_item_tag(user, tagged_item, tag_name, tag_value) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return tag_assoc def _get_item_tag_assoc(self, trans, item_class_name, id, tag_name): diff --git a/lib/galaxy/managers/jobs.py b/lib/galaxy/managers/jobs.py index 48c04b3e656f..d0a01c370797 100644 --- a/lib/galaxy/managers/jobs.py +++ b/lib/galaxy/managers/jobs.py @@ -65,7 +65,6 @@ WorkflowStep, YIELD_PER_ROWS, ) -from galaxy.model.base import transaction from galaxy.model.index_filter_util import ( raw_text_column_filter, text_column_filter, @@ -348,8 +347,7 @@ def stop(self, job, message=None): if not job.finished: job.mark_deleted(self.app.config.track_jobs_in_database) session = self.app.model.session - with transaction(session): - session.commit() + session.commit() self.app.job_manager.stop(job, message=message) return True else: diff --git a/lib/galaxy/managers/landing.py b/lib/galaxy/managers/landing.py index 5012d2280134..914d18445ffd 100644 --- a/lib/galaxy/managers/landing.py +++ b/lib/galaxy/managers/landing.py @@ -19,7 +19,6 @@ ToolLandingRequest as ToolLandingRequestModel, WorkflowLandingRequest as WorkflowLandingRequestModel, ) -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.schema.schema import ( ClaimLandingPayload, @@ -199,5 +198,4 @@ def _state(self, model: LandingRequestModel) -> LandingRequestState: def _save(self, model: LandingRequestModel): sa_session = self.sa_session sa_session.add(model) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() diff --git a/lib/galaxy/managers/libraries.py b/lib/galaxy/managers/libraries.py index 66e6903a01d1..05764c50bfeb 100644 --- a/lib/galaxy/managers/libraries.py +++ b/lib/galaxy/managers/libraries.py @@ -22,7 +22,6 @@ Library, Role, ) -from galaxy.model.base import transaction from galaxy.model.db.library import ( get_libraries_by_name, get_libraries_for_admins, @@ -78,8 +77,7 @@ def create(self, trans, name: str, description: Optional[str] = "", synopsis: Op root_folder = trans.app.model.LibraryFolder(name=name, description="") library.root_folder = root_folder trans.sa_session.add_all((library, root_folder)) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return library def update( @@ -116,8 +114,7 @@ def update( changed = True if changed: trans.sa_session.add(library) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return library def delete(self, trans, library: Library, undelete: Optional[bool] = False) -> Library: @@ -131,8 +128,7 @@ def delete(self, trans, library: Library, undelete: Optional[bool] = False) -> L else: library.deleted = True trans.sa_session.add(library) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return library def list(self, trans, deleted: Optional[bool] = False) -> Tuple[Query, Dict[str, Set]]: diff --git a/lib/galaxy/managers/library_datasets.py b/lib/galaxy/managers/library_datasets.py index 29005f42c651..56d9e9fa82f1 100644 --- a/lib/galaxy/managers/library_datasets.py +++ b/lib/galaxy/managers/library_datasets.py @@ -23,7 +23,6 @@ LibraryDatasetDatasetAssociation, LibraryFolder, ) -from galaxy.model.base import transaction from galaxy.structured_app import MinimalManagerApp from galaxy.util import validation @@ -133,8 +132,7 @@ def _set_from_dict( session = self.session() session.add(ldda) if flush: - with transaction(session): - session.commit() + session.commit() def _validate_and_parse_update_payload(self, payload): MINIMUM_STRING_LENGTH = 1 diff --git a/lib/galaxy/managers/model_stores.py b/lib/galaxy/managers/model_stores.py index 2524f5fac095..c5c8a93a1455 100644 --- a/lib/galaxy/managers/model_stores.py +++ b/lib/galaxy/managers/model_stores.py @@ -10,7 +10,6 @@ from galaxy.managers.export_tracker import StoreExportTracker from galaxy.managers.histories import HistoryManager from galaxy.managers.users import UserManager -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.model.store import ( DirectoryModelExportStore, @@ -103,8 +102,7 @@ def setup_history_export_job(self, request: SetupHistoryExportJob): job = self._sa_session.get(model.Job, job_id) assert job job.state = model.Job.states.NEW - with transaction(self._sa_session): - self._sa_session.commit() + self._sa_session.commit() self._job_manager.enqueue(job) def prepare_history_download(self, request: GenerateHistoryDownload): diff --git a/lib/galaxy/managers/notification.py b/lib/galaxy/managers/notification.py index 6bd99278e59a..3e2983db2a54 100644 --- a/lib/galaxy/managers/notification.py +++ b/lib/galaxy/managers/notification.py @@ -49,7 +49,6 @@ UserNotificationAssociation, UserRoleAssociation, ) -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.schema.notifications import ( AnyNotificationContent, @@ -164,12 +163,10 @@ def send_notification_to_recipients(self, request: NotificationCreateRequest) -> recipient_users = self.recipient_resolver.resolve(request.recipients) notification = self._create_notification_model(request.notification, request.galaxy_url) self.sa_session.add(notification) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() notifications_sent = self._create_associations(notification, recipient_users) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return notification, notifications_sent @@ -199,8 +196,7 @@ def dispatch_pending_notifications_via_channels(self) -> int: for notification in pending_notifications: notification.dispatched = True - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() # Do the actual dispatching for notification in pending_notifications: @@ -284,8 +280,7 @@ def create_broadcast_notification(self, request: BroadcastNotificationCreateRequ self.ensure_notifications_enabled() notification = self._create_notification_model(request) self.sa_session.add(notification) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return notification def get_user_notification(self, user: User, notification_id: int, active_only: Optional[bool] = True): @@ -383,8 +378,7 @@ def update_user_notifications( stmt = stmt.values(deleted=request.deleted) result = self.sa_session.execute(stmt) updated_row_count = result.rowcount - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return updated_row_count def update_broadcasted_notification(self, notification_id: int, request: NotificationBroadcastUpdateRequest) -> int: @@ -408,8 +402,7 @@ def update_broadcasted_notification(self, notification_id: int, request: Notific stmt = stmt.values(content=request.content.json()) result = self.sa_session.execute(stmt) updated_row_count = result.rowcount - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return updated_row_count def get_user_notification_preferences(self, user: User) -> UserNotificationPreferences: @@ -430,8 +423,7 @@ def update_user_notification_preferences( preferences = self.get_user_notification_preferences(user) preferences.update(request.preferences) user.preferences[NOTIFICATION_PREFERENCES_SECTION_NAME] = preferences.model_dump_json() - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return preferences def _register_supported_channels(self) -> Dict[str, NotificationChannelPlugin]: @@ -469,8 +461,7 @@ def cleanup_expired_notifications(self) -> CleanupResultSummary: result = self.sa_session.execute(delete_stmt) deleted_notifications_count = result.rowcount - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return CleanupResultSummary(deleted_notifications_count, deleted_associations_count) diff --git a/lib/galaxy/managers/pages.py b/lib/galaxy/managers/pages.py index 101d785c688e..fcf0f860fa8f 100644 --- a/lib/galaxy/managers/pages.py +++ b/lib/galaxy/managers/pages.py @@ -54,7 +54,6 @@ User, Visualization, ) -from galaxy.model.base import transaction from galaxy.model.index_filter_util import ( append_user_filter, raw_text_column_filter, @@ -284,8 +283,7 @@ def create_page(self, trans, payload: CreatePagePayload): # Persist session = trans.sa_session session.add(page) - with transaction(session): - session.commit() + session.commit() return page def save_new_revision(self, trans, page, payload): @@ -317,8 +315,7 @@ def save_new_revision(self, trans, page, payload): # Persist session = trans.sa_session - with transaction(session): - session.commit() + session.commit() return page_revision def rewrite_content_for_import(self, trans, content, content_format: str): diff --git a/lib/galaxy/managers/quotas.py b/lib/galaxy/managers/quotas.py index 932e77a91348..8801f2cc304c 100644 --- a/lib/galaxy/managers/quotas.py +++ b/lib/galaxy/managers/quotas.py @@ -28,7 +28,6 @@ Quota, User, ) -from galaxy.model.base import transaction from galaxy.quota import DatabaseQuotaAgent from galaxy.quota._schema import ( CreateQuotaParams, @@ -104,8 +103,7 @@ def create_quota(self, payload: dict, decode_id=None) -> Tuple[model.Quota, str] self.sa_session.add(gqa) message = f"Quota '{quota.name}' has been created with {len(in_users)} associated users and {len(in_groups)} associated groups." - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return quota, message @@ -129,8 +127,7 @@ def rename_quota(self, quota, params) -> Optional[str]: if params.description: quota.description = params.description self.sa_session.add(quota) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() if old_name != params.name: return f"Quota '{old_name}' has been renamed to '{params.name}'." else: @@ -182,8 +179,7 @@ def edit_quota(self, quota, params) -> Optional[str]: quota.amount = new_amount quota.operation = params.operation self.sa_session.add(quota) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() if old_display_amount != quota.display_amount or old_operation != quota.operation: return f"Quota '{quota.name}' is now '{quota.operation}{quota.display_amount}'." else: @@ -201,8 +197,7 @@ def set_quota_default(self, quota, params) -> Optional[str]: message = f"Quota '{quota.name}' is no longer the default for {quota.default[0].type} users." for dqa in quota.default: self.sa_session.delete(dqa) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return message def unset_quota_default(self, quota, params=None) -> Optional[str]: @@ -211,8 +206,7 @@ def unset_quota_default(self, quota, params=None) -> Optional[str]: message = f"Quota '{quota.name}' is no longer the default for {quota.default[0].type} users." for dqa in quota.default: self.sa_session.delete(dqa) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return message def delete_quota(self, quota, params=None) -> str: @@ -232,8 +226,7 @@ def delete_quota(self, quota, params=None) -> str: q.deleted = True self.sa_session.add(q) names.append(q.name) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() message += ", ".join(names) return message @@ -252,8 +245,7 @@ def undelete_quota(self, quota, params=None) -> str: q.deleted = False self.sa_session.add(q) names.append(q.name) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() message += ", ".join(names) return message @@ -282,8 +274,7 @@ def purge_quota(self, quota, params=None) -> str: for gqa in q.groups: self.sa_session.delete(gqa) names.append(q.name) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() message += ", ".join(names) return message diff --git a/lib/galaxy/managers/ratable.py b/lib/galaxy/managers/ratable.py index 2acc148a6b95..9551f1403f3b 100644 --- a/lib/galaxy/managers/ratable.py +++ b/lib/galaxy/managers/ratable.py @@ -9,7 +9,6 @@ from sqlalchemy.sql.expression import func from galaxy.model import ItemRatingAssociation -from galaxy.model.base import transaction from . import base log = logging.getLogger(__name__) @@ -59,8 +58,7 @@ def rate(self, item, user, value, flush=True): self.session().add(rating) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return rating # TODO?: all ratings for a user diff --git a/lib/galaxy/managers/rbac_secured.py b/lib/galaxy/managers/rbac_secured.py index 41f24da24809..4a3507f3d699 100644 --- a/lib/galaxy/managers/rbac_secured.py +++ b/lib/galaxy/managers/rbac_secured.py @@ -6,7 +6,6 @@ security, ) from galaxy.managers import users -from galaxy.model.base import transaction log = logging.getLogger(__name__) @@ -112,8 +111,7 @@ def set(self, dataset, roles, flush=True): permissions.append(self._create(dataset, role, flush=False)) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return permissions def clear(self, dataset, flush=True): @@ -126,8 +124,7 @@ def _create(self, dataset, role, flush=True): self.session().add(permission) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return permission def _roles(self, dataset): @@ -148,8 +145,7 @@ def _delete(self, permissions, flush=True): self.session().delete(permission) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() def _revoke_role(self, dataset, role, flush=True): role_permissions = self.by_roles(dataset, [role]) diff --git a/lib/galaxy/managers/roles.py b/lib/galaxy/managers/roles.py index 02448c1a4fbc..8d15c9ee0368 100644 --- a/lib/galaxy/managers/roles.py +++ b/lib/galaxy/managers/roles.py @@ -25,7 +25,6 @@ from galaxy.managers import base from galaxy.managers.context import ProvidesUserContext from galaxy.model import Role -from galaxy.model.base import transaction from galaxy.schema.schema import RoleDefinitionModel from galaxy.util import unicodify @@ -107,15 +106,13 @@ def create_role(self, trans: ProvidesUserContext, role_definition_model: RoleDef for group in groups: trans.app.security_agent.associate_group_role(group, role) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return role def delete(self, trans: ProvidesUserContext, role: model.Role) -> model.Role: role.deleted = True trans.sa_session.add(role) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return role def purge(self, trans: ProvidesUserContext, role: model.Role) -> model.Role: @@ -151,8 +148,7 @@ def purge(self, trans: ProvidesUserContext, role: model.Role) -> model.Role: sa_session.delete(dp) # Delete the role sa_session.delete(role) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() return role def undelete(self, trans: ProvidesUserContext, role: model.Role) -> model.Role: @@ -162,6 +158,5 @@ def undelete(self, trans: ProvidesUserContext, role: model.Role) -> model.Role: ) role.deleted = False trans.sa_session.add(role) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return role diff --git a/lib/galaxy/managers/sharable.py b/lib/galaxy/managers/sharable.py index 1d6c447cd59b..e45332380877 100644 --- a/lib/galaxy/managers/sharable.py +++ b/lib/galaxy/managers/sharable.py @@ -44,7 +44,6 @@ User, UserShareAssociation, ) -from galaxy.model.base import transaction from galaxy.model.tags import GalaxyTagHandler from galaxy.schema.schema import ( ShareWithExtra, @@ -199,8 +198,7 @@ def _create_user_share_assoc(self, item, user, flush=True): if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return user_share_assoc def unshare_with(self, item, user: User, flush: bool = True): @@ -212,8 +210,7 @@ def unshare_with(self, item, user: User, flush: bool = True): self.session().delete(user_share_assoc) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return user_share_assoc def _query_shared_with(self, user, eagerloads=True, **kwargs): @@ -279,8 +276,7 @@ def update_current_sharing_with_users(self, item, new_users_shared_with: Set[Use if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return current_shares, needs_adding, needs_removing # .... slugs @@ -305,8 +301,7 @@ def set_slug(self, item, new_slug, user, flush=True): item.slug = new_slug if flush: - with transaction(session): - session.commit() + session.commit() return item def _default_slug_base(self, item): @@ -348,8 +343,7 @@ def create_unique_slug(self, item, flush=True): self.session().add(item) if flush: session = self.session() - with transaction(session): - session.commit() + session.commit() return item # TODO: def by_slug( self, user, **kwargs ): diff --git a/lib/galaxy/managers/tags.py b/lib/galaxy/managers/tags.py index 452b23489c3d..eaf19cf1e5b9 100644 --- a/lib/galaxy/managers/tags.py +++ b/lib/galaxy/managers/tags.py @@ -4,7 +4,6 @@ from pydantic import Field from galaxy.managers.context import ProvidesUserContext -from galaxy.model.base import transaction from galaxy.model.tags import GalaxyTagHandlerSession from galaxy.schema.fields import DecodedDatabaseIdField from galaxy.schema.schema import ( @@ -53,8 +52,7 @@ def update(self, trans: ProvidesUserContext, payload: ItemTagsPayload) -> None: item = self._get_item(trans.tag_handler, payload) trans.tag_handler.delete_item_tags(user, item) trans.tag_handler.apply_item_tags(user, item, new_tags) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def _get_item(self, tag_handler: GalaxyTagHandlerSession, payload: ItemTagsPayload): """ diff --git a/lib/galaxy/managers/users.py b/lib/galaxy/managers/users.py index d1f24e4cb0b6..6027d1cba007 100644 --- a/lib/galaxy/managers/users.py +++ b/lib/galaxy/managers/users.py @@ -44,7 +44,6 @@ UserAddress, UserQuotaUsage, ) -from galaxy.model.base import transaction from galaxy.model.db.user import ( _cleanup_nonprivate_user_roles, get_user_by_email, @@ -171,8 +170,7 @@ def _stop_all_jobs_from_user(self, user): session = self.session() for job in active_jobs: job.mark_deleted(self.app.config.track_jobs_in_database) - with transaction(session): - session.commit() + session.commit() def _get_all_active_jobs_from_user(self, user: User) -> List[Job]: """Get all jobs that are not ready yet and belong to the given user.""" @@ -515,8 +513,7 @@ def __set_password(self, trans, user, password, confirm): other_galaxy_session.is_valid = False trans.sa_session.add(other_galaxy_session) trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() trans.log_event("User change password") else: return "Failed to determine user, access denied." @@ -575,8 +572,7 @@ def __get_activation_token(self, trans, email): activation_token = util.hash_util.new_secure_hash_v2(str(random.getrandbits(256))) user.activation_token = activation_token trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return activation_token def send_reset_email(self, trans, payload, **kwd): @@ -603,8 +599,7 @@ def send_reset_email(self, trans, payload, **kwd): try: util.send_mail(trans.app.config.email_from, email, subject, body, self.app.config) trans.sa_session.add(reset_user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() trans.log_event(f"User reset password: {email}") except Exception as e: log.debug(body) @@ -620,8 +615,7 @@ def get_reset_token(self, trans, email): if reset_user and not reset_user.deleted: prt = self.app.model.PasswordResetToken(reset_user) trans.sa_session.add(prt) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return reset_user, prt return None, None @@ -643,8 +637,7 @@ def activate(self, user): user.active = True self.session().add(user) session = self.session() - with transaction(session): - session.commit() + session.commit() def get_or_create_remote_user(self, remote_user_email): """ @@ -669,8 +662,7 @@ def get_or_create_remote_user(self, remote_user_email): user.external = True user.username = username_from_email(self.session(), remote_user_email, self.app.model.User) self.session().add(user) - with transaction(self.session()): - self.session().commit() + self.session().commit() self.app.security_agent.create_private_user_role(user) # We set default user permissions, before we log in and set the default history permissions if self.app_type == "galaxy": diff --git a/lib/galaxy/managers/workflows.py b/lib/galaxy/managers/workflows.py index 162596abb1ff..63290d7ab1d8 100644 --- a/lib/galaxy/managers/workflows.py +++ b/lib/galaxy/managers/workflows.py @@ -81,10 +81,7 @@ WorkflowInvocationStep, WorkflowInvocationToSubworkflowInvocationAssociation, ) -from galaxy.model.base import ( - ensure_object_added_to_session, - transaction, -) +from galaxy.model.base import ensure_object_added_to_session from galaxy.model.index_filter_util import ( append_user_filter, raw_text_column_filter, @@ -340,8 +337,7 @@ def attach_stored_workflow(self, trans, workflow): user=trans.user, name=workflow.name, workflow=workflow, hidden=True ) trans.sa_session.add(stored_workflow) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return stored_workflow def get_owned_workflow(self, trans, encoded_workflow_id): @@ -464,8 +460,7 @@ def request_invocation_cancellation(self, trans, decoded_invocation_id: int): workflow_invocation.add_message(InvocationCancellationUserRequest(reason="user_request")) trans.sa_session.add(workflow_invocation) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return workflow_invocation @@ -502,8 +497,7 @@ def update_invocation_step(self, trans, decoded_workflow_invocation_step_id, act performed_action = module.do_invocation_step_action(step, action) workflow_invocation_step.action = performed_action trans.sa_session.add(workflow_invocation_step) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return workflow_invocation_step def build_invocations_query( @@ -719,8 +713,7 @@ def build_workflow_from_raw_description( menuEntry.stored_workflow = stored trans.user.stored_workflow_menu_entries.append(menuEntry) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return CreatedWorkflow(stored_workflow=stored, workflow=workflow, missing_tools=missing_tool_tups) @@ -782,8 +775,7 @@ def update_workflow_from_raw_description( # Persist if not dry_run: - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if stored_workflow.from_path: self._sync_stored_workflow(trans, stored_workflow) # Return something informative From 74e4c97f637e7362817f803d9a2c19e9a3e98882 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 16:57:47 -0500 Subject: [PATCH 15/39] Remove transaction helper from galaxy.quota --- lib/galaxy/quota/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/galaxy/quota/__init__.py b/lib/galaxy/quota/__init__.py index 3f0b55cda645..71a56aeed080 100644 --- a/lib/galaxy/quota/__init__.py +++ b/lib/galaxy/quota/__init__.py @@ -7,7 +7,6 @@ from sqlalchemy.sql import text import galaxy.util -from galaxy.model.base import transaction log = logging.getLogger(__name__) @@ -325,8 +324,7 @@ def set_default_quota(self, default_type, quota): else: target_default = self.model.DefaultQuotaAssociation(default_type, quota) self.sa_session.add(target_default) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def get_percent( self, trans=None, user=False, history=False, usage=False, quota=False, quota_source_label=None @@ -366,16 +364,14 @@ def set_entity_quota_associations(self, quotas=None, users=None, groups=None, de self.sa_session.delete(a) flush_needed = True if flush_needed: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() for user in users: uqa = self.model.UserQuotaAssociation(user, quota) self.sa_session.add(uqa) for group in groups: gqa = self.model.GroupQuotaAssociation(group, quota) self.sa_session.add(gqa) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def is_over_quota(self, app, job, job_destination): # Doesn't work because job.object_store_id until inside handler :_( From bc13d78b359a34e8efc8f2e8d623f4650342110b Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 16:59:38 -0500 Subject: [PATCH 16/39] Remove transaction helper from galaxy.celery --- lib/galaxy/celery/base_task.py | 67 ++++++++++++++++------------------ lib/galaxy/celery/tasks.py | 10 ++--- 2 files changed, 34 insertions(+), 43 deletions(-) diff --git a/lib/galaxy/celery/base_task.py b/lib/galaxy/celery/base_task.py index c4e986cc94b6..9ab36837c1d8 100644 --- a/lib/galaxy/celery/base_task.py +++ b/lib/galaxy/celery/base_task.py @@ -13,7 +13,6 @@ from sqlalchemy.exc import IntegrityError from galaxy.model import CeleryUserRateLimit -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session @@ -83,25 +82,24 @@ class GalaxyTaskBeforeStartUserRateLimitPostgres(GalaxyTaskBeforeStartUserRateLi def calculate_task_start_time( self, user_id: int, sa_session: galaxy_scoped_session, task_interval_secs: float, now: datetime.datetime ) -> datetime.datetime: - with transaction(sa_session): - update_stmt = ( - update(CeleryUserRateLimit) - .where(CeleryUserRateLimit.user_id == user_id) - .values(last_scheduled_time=text("greatest(last_scheduled_time + ':interval second', :now)")) + update_stmt = ( + update(CeleryUserRateLimit) + .where(CeleryUserRateLimit.user_id == user_id) + .values(last_scheduled_time=text("greatest(last_scheduled_time + ':interval second', :now)")) + .returning(CeleryUserRateLimit.last_scheduled_time) + ) + result = sa_session.execute(update_stmt, {"interval": task_interval_secs, "now": now}).all() + if not result: + sched_time = now + datetime.timedelta(seconds=task_interval_secs) + upsert_stmt = ( + ps_insert(CeleryUserRateLimit) # type:ignore[attr-defined] + .values(user_id=user_id, last_scheduled_time=now) .returning(CeleryUserRateLimit.last_scheduled_time) + .on_conflict_do_update(index_elements=["user_id"], set_=dict(last_scheduled_time=sched_time)) ) - result = sa_session.execute(update_stmt, {"interval": task_interval_secs, "now": now}).all() - if not result: - sched_time = now + datetime.timedelta(seconds=task_interval_secs) - upsert_stmt = ( - ps_insert(CeleryUserRateLimit) # type:ignore[attr-defined] - .values(user_id=user_id, last_scheduled_time=now) - .returning(CeleryUserRateLimit.last_scheduled_time) - .on_conflict_do_update(index_elements=["user_id"], set_=dict(last_scheduled_time=sched_time)) - ) - result = sa_session.execute(upsert_stmt).all() - sa_session.commit() - return result[0][0] + result = sa_session.execute(upsert_stmt).all() + sa_session.commit() + return result[0][0] class GalaxyTaskBeforeStartUserRateLimitStandard(GalaxyTaskBeforeStartUserRateLimit): @@ -130,26 +128,23 @@ def calculate_task_start_time( self, user_id: int, sa_session: galaxy_scoped_session, task_interval_secs: float, now: datetime.datetime ) -> datetime.datetime: last_scheduled_time = None - with transaction(sa_session): - last_scheduled_time = sa_session.scalars(self._select_stmt, {"userid": user_id}).first() - if last_scheduled_time: - sched_time = last_scheduled_time + datetime.timedelta(seconds=task_interval_secs) - if sched_time < now: - sched_time = now - sa_session.execute(self._update_stmt, {"userid": user_id, "sched_time": sched_time}) - sa_session.commit() + last_scheduled_time = sa_session.scalars(self._select_stmt, {"userid": user_id}).first() + if last_scheduled_time: + sched_time = last_scheduled_time + datetime.timedelta(seconds=task_interval_secs) + if sched_time < now: + sched_time = now + sa_session.execute(self._update_stmt, {"userid": user_id, "sched_time": sched_time}) + sa_session.commit() if not last_scheduled_time: try: - with transaction(sa_session): - sched_time = now - sa_session.execute(self._insert_stmt, {"userid": user_id, "sched_time": sched_time}) - sa_session.commit() + sched_time = now + sa_session.execute(self._insert_stmt, {"userid": user_id, "sched_time": sched_time}) + sa_session.commit() except IntegrityError: # Row was inserted by another thread since we tried the update above. - with transaction(sa_session): - sched_time = now + datetime.timedelta(seconds=task_interval_secs) - result = sa_session.execute(self._update_stmt, {"userid": user_id, "sched_time": sched_time}) - if result.rowcount == 0: - raise Exception(f"Failed to update a celery_user_rate_limit row for user id {user_id}") - sa_session.commit() + sched_time = now + datetime.timedelta(seconds=task_interval_secs) + result = sa_session.execute(self._update_stmt, {"userid": user_id, "sched_time": sched_time}) + if result.rowcount == 0: + raise Exception(f"Failed to update a celery_user_rate_limit row for user id {user_id}") + sa_session.commit() return sched_time diff --git a/lib/galaxy/celery/tasks.py b/lib/galaxy/celery/tasks.py index 7c1d75dbb86a..9265e2815e38 100644 --- a/lib/galaxy/celery/tasks.py +++ b/lib/galaxy/celery/tasks.py @@ -41,7 +41,6 @@ Job, User, ) -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.objectstore import BaseObjectStore from galaxy.objectstore.caching import check_caches @@ -157,8 +156,7 @@ def change_datatype( path = dataset_instance.dataset.get_file_name() datatype = sniff.guess_ext(path, datatypes_registry.sniff_order) datatypes_registry.change_datatype(dataset_instance, datatype) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() set_metadata(hda_manager, ldda_manager, sa_session, dataset_id, model_class) @@ -174,8 +172,7 @@ def touch( stmt = select(model.HistoryDatasetCollectionAssociation).filter_by(id=item_id) item = sa_session.execute(stmt).scalar_one() item.touch() - with transaction(sa_session): - sa_session.commit() + sa_session.commit() @galaxy_task(action="set dataset association metadata") @@ -209,8 +206,7 @@ def set_metadata( except Exception as e: log.info(f"Setting metadata failed on {model_class} {dataset_instance.id}: {str(e)}") dataset_instance.state = dataset_instance.states.FAILED_METADATA - with transaction(sa_session): - sa_session.commit() + sa_session.commit() def _get_dataset_manager( From 6125c2e2c7e56f7e2ee4b2c501b51cb8130815e1 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:01:12 -0500 Subject: [PATCH 17/39] Remove transaction helper from galaxy.app_unittest_utils --- lib/galaxy/app_unittest_utils/galaxy_mock.py | 4 +--- lib/galaxy/app_unittest_utils/toolbox_support.py | 13 ++++--------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/galaxy/app_unittest_utils/galaxy_mock.py b/lib/galaxy/app_unittest_utils/galaxy_mock.py index 4e6eb43042cf..ee93c3421609 100644 --- a/lib/galaxy/app_unittest_utils/galaxy_mock.py +++ b/lib/galaxy/app_unittest_utils/galaxy_mock.py @@ -36,7 +36,6 @@ from galaxy.model.base import ( ModelMapping, SharedModelMapping, - transaction, ) from galaxy.model.mapping import GalaxyModelMapping from galaxy.model.scoped_session import galaxy_scoped_session @@ -357,8 +356,7 @@ def set_user(self, user): if self.galaxy_session: self.galaxy_session.user = user self.sa_session.add(self.galaxy_session) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() self.__user = user user = property(get_user, set_user) diff --git a/lib/galaxy/app_unittest_utils/toolbox_support.py b/lib/galaxy/app_unittest_utils/toolbox_support.py index 1189e4580b84..65a8340c9208 100644 --- a/lib/galaxy/app_unittest_utils/toolbox_support.py +++ b/lib/galaxy/app_unittest_utils/toolbox_support.py @@ -8,7 +8,6 @@ from galaxy.app_unittest_utils.tools_support import UsesTools from galaxy.config_watchers import ConfigWatchers from galaxy.model import tool_shed_install -from galaxy.model.base import transaction from galaxy.model.tool_shed_install import mapping from galaxy.tools import ToolBox from galaxy.tools.cache import ToolCache @@ -113,8 +112,7 @@ def _repo_install(self, changeset, config_filename=None): repository.uninstalled = False self.app.install_model.context.add(repository) session = self.app.install_model.context - with transaction(session): - session.commit() + session.commit() return repository def _setup_two_versions(self): @@ -123,16 +121,14 @@ def _setup_two_versions(self): version1.tool_id = "github.com/galaxyproject/example/test_tool/0.1" self.app.install_model.context.add(version1) session = self.app.install_model.context - with transaction(session): - session.commit() + session.commit() self._repo_install(changeset="2") version2 = tool_shed_install.ToolVersion() version2.tool_id = "github.com/galaxyproject/example/test_tool/0.2" self.app.install_model.context.add(version2) session = self.app.install_model.context - with transaction(session): - session.commit() + session.commit() version_association = tool_shed_install.ToolVersionAssociation() version_association.parent_id = version1.id @@ -140,8 +136,7 @@ def _setup_two_versions(self): self.app.install_model.context.add(version_association) session = self.app.install_model.context - with transaction(session): - session.commit() + session.commit() def _setup_two_versions_in_config(self, section=False): if section: From 8af74a86870c2669dc6c1da4f20e26da4c10bb20 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:01:51 -0500 Subject: [PATCH 18/39] Remove transaction helper from galaxy.work --- lib/galaxy/work/context.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/galaxy/work/context.py b/lib/galaxy/work/context.py index 801c0d9e7e77..e723e069109c 100644 --- a/lib/galaxy/work/context.py +++ b/lib/galaxy/work/context.py @@ -15,7 +15,6 @@ History, Role, ) -from galaxy.model.base import transaction class WorkRequestContext(ProvidesHistoryContext): @@ -168,8 +167,7 @@ def set_history(self, history): if history and not history.deleted and self.galaxy_session: self.galaxy_session.current_history = history self.sa_session.add(self.galaxy_session) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def proxy_work_context_for_history( From e65045eb9ab815fd04467131cb4c21f265a24549 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:02:56 -0500 Subject: [PATCH 19/39] Remove transaction helper from galaxy.authnz --- lib/galaxy/authnz/custos_authnz.py | 10 +++------- lib/galaxy/authnz/psa_authnz.py | 4 +--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/authnz/custos_authnz.py b/lib/galaxy/authnz/custos_authnz.py index 4343f1554fd2..03fdf05bccf8 100644 --- a/lib/galaxy/authnz/custos_authnz.py +++ b/lib/galaxy/authnz/custos_authnz.py @@ -27,7 +27,6 @@ CustosAuthnzToken, User, ) -from galaxy.model.base import transaction from galaxy.model.orm.util import add_object_to_object_session from galaxy.util import requests from . import IdentityProvider @@ -293,8 +292,7 @@ def callback(self, state_token, authz_code, trans, login_redirect_url): redirect_url = "/" trans.sa_session.add(custos_authnz_token) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return redirect_url, custos_authnz_token.user @@ -342,8 +340,7 @@ def create_user(self, token, trans, login_redirect_url): trans.sa_session.add(user) trans.sa_session.add(custos_authnz_token) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return login_redirect_url, user def disconnect(self, provider, trans, disconnect_redirect_url=None, email=None, association_id=None): @@ -360,8 +357,7 @@ def disconnect(self, provider, trans, disconnect_redirect_url=None, email=None, if id_token_decoded["email"] == email: index = idx trans.sa_session.delete(provider_tokens[index]) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return True, "", disconnect_redirect_url except Exception as e: return False, f"Failed to disconnect provider {provider}: {util.unicodify(e)}", None diff --git a/lib/galaxy/authnz/psa_authnz.py b/lib/galaxy/authnz/psa_authnz.py index c1299966a839..e5d1b536b0b3 100644 --- a/lib/galaxy/authnz/psa_authnz.py +++ b/lib/galaxy/authnz/psa_authnz.py @@ -25,7 +25,6 @@ PSAPartial, UserAuthnzToken, ) -from galaxy.model.base import transaction from galaxy.util import ( DEFAULT_SOCKET_TIMEOUT, requests, @@ -494,5 +493,4 @@ def disconnect( sa_session.delete(user_authnz) # option B # user_authnz.extra_data = None - with transaction(sa_session): - sa_session.commit() + sa_session.commit() From 7275332f879d497c7c7443ff6e12d05c61bba648 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:04:47 -0500 Subject: [PATCH 20/39] Remove transaction helper from galaxy.workflow --- lib/galaxy/workflow/extract.py | 8 ++------ lib/galaxy/workflow/run.py | 8 ++------ lib/galaxy/workflow/run_request.py | 8 ++------ lib/galaxy/workflow/scheduling_manager.py | 7 ++----- 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/lib/galaxy/workflow/extract.py b/lib/galaxy/workflow/extract.py index 76b5c6212c86..60f8a64a79c1 100644 --- a/lib/galaxy/workflow/extract.py +++ b/lib/galaxy/workflow/extract.py @@ -9,10 +9,7 @@ exceptions, model, ) -from galaxy.model.base import ( - ensure_object_added_to_session, - transaction, -) +from galaxy.model.base import ensure_object_added_to_session from galaxy.tool_util.parser import ToolOutputCollectionPart from galaxy.tools.parameters.basic import ( DataCollectionToolParameter, @@ -76,8 +73,7 @@ def extract_workflow( stored.latest_workflow = workflow trans.sa_session.add(stored) ensure_object_added_to_session(workflow, session=trans.sa_session) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return stored diff --git a/lib/galaxy/workflow/run.py b/lib/galaxy/workflow/run.py index 6d52a7f6a0cf..6eb9918111c3 100644 --- a/lib/galaxy/workflow/run.py +++ b/lib/galaxy/workflow/run.py @@ -20,10 +20,7 @@ WorkflowInvocation, WorkflowInvocationStep, ) -from galaxy.model.base import ( - ensure_object_added_to_session, - transaction, -) +from galaxy.model.base import ensure_object_added_to_session from galaxy.schema.invocation import ( CancelReason, FAILURE_REASONS_EXPECTED, @@ -126,8 +123,7 @@ def __invoke( # Be sure to update state of workflow_invocation. trans.sa_session.add(workflow_invocation) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return outputs, workflow_invocation diff --git a/lib/galaxy/workflow/run_request.py b/lib/galaxy/workflow/run_request.py index 94b47feeec31..42579c5543fc 100644 --- a/lib/galaxy/workflow/run_request.py +++ b/lib/galaxy/workflow/run_request.py @@ -23,10 +23,7 @@ WorkflowRequestInputParameter, WorkflowRequestStepState, ) -from galaxy.model.base import ( - ensure_object_added_to_session, - transaction, -) +from galaxy.model.base import ensure_object_added_to_session from galaxy.tool_util.parameters import DataRequestUri from galaxy.tools.parameters.basic import ParameterValueError from galaxy.tools.parameters.meta import expand_workflow_inputs @@ -293,8 +290,7 @@ def _get_target_history( nh_name = f"{nh_name} on {', '.join(ids[0:-1])} and {ids[-1]}" new_history = History(user=trans.user, name=nh_name) trans.sa_session.add(new_history) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() target_history = new_history return target_history diff --git a/lib/galaxy/workflow/scheduling_manager.py b/lib/galaxy/workflow/scheduling_manager.py index a68f42aa8933..e30c90c74fb0 100644 --- a/lib/galaxy/workflow/scheduling_manager.py +++ b/lib/galaxy/workflow/scheduling_manager.py @@ -6,7 +6,6 @@ from galaxy import model from galaxy.exceptions import HandlerAssignmentError from galaxy.jobs.handler import InvocationGrabber -from galaxy.model.base import transaction from galaxy.schema.invocation import ( FailureReason, InvocationFailureDatasetFailed, @@ -99,8 +98,7 @@ def _handle_setup_msg(self, workflow_invocation_id=None): if workflow_invocation.handler is None: workflow_invocation.handler = self.app.config.server_name sa_session.add(workflow_invocation) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() else: log.warning( "(%s) Handler '%s' received setup message for workflow invocation but handler '%s' is" @@ -124,8 +122,7 @@ def _queue_callback(self, workflow_invocation): workflow_invocation.handler = self.app.config.server_name sa_session = self.app.model.context sa_session.add(workflow_invocation) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() def _message_callback(self, workflow_invocation): return WorkflowSchedulingMessage(task="setup", workflow_invocation_id=workflow_invocation.id) From 85b9697a9008e67d19cf0ad32403fea57e028e69 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:05:19 -0500 Subject: [PATCH 21/39] Remove transaction helper from galaxy.actions --- lib/galaxy/actions/library.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/actions/library.py b/lib/galaxy/actions/library.py index 8afb8d4f2275..ca1a0a906a6c 100644 --- a/lib/galaxy/actions/library.py +++ b/lib/galaxy/actions/library.py @@ -17,7 +17,6 @@ dictify_dataset_collection_instance, ) from galaxy.model import LibraryFolder -from galaxy.model.base import transaction from galaxy.tools.actions import upload_common from galaxy.tools.parameters import populate_state from galaxy.util.path import ( @@ -294,8 +293,7 @@ def _make_library_uploaded_dataset(self, trans, params, name, path, type, librar if link_data_only == "link_to_files": uploaded_dataset.data.link_to(path) trans.sa_session.add_all((uploaded_dataset.data, uploaded_dataset.data.dataset)) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return uploaded_dataset def _upload_library_dataset(self, trans, payload): @@ -335,8 +333,7 @@ def _create_folder(self, trans, payload): new_folder.genome_build = trans.app.genome_builds.default_value parent_folder.add_folder(new_folder) trans.sa_session.add(new_folder) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # New folders default to having the same permissions as their parent folder trans.app.security_agent.copy_library_permissions(trans, parent_folder, new_folder) new_folder_dict = dict(created=new_folder) From b8fe28d86d4801ed8dec9b95d539c83de0853b70 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:07:55 -0500 Subject: [PATCH 22/39] Remove transaction helper from galaxy.jobs --- lib/galaxy/jobs/__init__.py | 49 ++++++------------- lib/galaxy/jobs/handler.py | 11 ++--- lib/galaxy/jobs/runners/__init__.py | 8 +-- .../jobs/runners/state_handlers/resubmit.py | 4 +- lib/galaxy/jobs/runners/tasks.py | 7 +-- 5 files changed, 24 insertions(+), 55 deletions(-) diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index ddfb5f01102f..c887fe833666 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -68,7 +68,6 @@ store, Task, ) -from galaxy.model.base import transaction from galaxy.model.store import copy_dataset_instance_metadata_attributes from galaxy.model.store.discover import MaxDiscoveredFilesExceededError from galaxy.objectstore import ( @@ -1284,8 +1283,7 @@ def get_special(): ) job.dependencies = self.tool.dependencies self.sa_session.add(job) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() log.debug(f"Job wrapper for Job [{job.id}] prepared {prepare_timer}") def _setup_working_directory(self, job=None): @@ -1487,8 +1485,7 @@ def fail( job.exit_code = exit_code self.sa_session.add(job) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() else: for dataset_assoc in job.output_datasets: dataset = dataset_assoc.dataset @@ -1547,8 +1544,7 @@ def mark_as_resubmitted(self, info=None): job.info = info job.set_state(Job.states.RESUBMITTED) self.sa_session.add(job) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def change_state(self, state, info=False, flush=True, job=None): if job is None: @@ -1575,8 +1571,7 @@ def change_state(self, state, info=False, flush=True, job=None): if state_changed: job.update_output_states(self.app.application_stack.supports_skip_locked()) if flush: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def get_state(self) -> str: job = self.get_job() @@ -1593,8 +1588,7 @@ def set_external_id(self, external_id, job=None, flush=True): job.job_runner_external_id = external_id self.sa_session.add(job) if flush: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() @property def home_target(self): @@ -1620,8 +1614,7 @@ def enqueue(self): self.set_job_destination(self.job_destination, None, flush=False, job=job) # Set object store after job destination so can leverage parameters... self._set_object_store_ids(job) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return True def set_job_destination(self, job_destination, external_id=None, flush=True, job=None): @@ -2098,8 +2091,7 @@ def fail(message=job.info, exception=None): # differently and deadlocks can occur (one thread updates user and # waits on invocation and the other updates invocation and waits on # user). - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() # Finally set the job state. This should only happen *after* all # dataset creation, and will allow us to eliminate force_history_refresh. @@ -2107,8 +2099,7 @@ def fail(message=job.info, exception=None): if not job.tasks: # If job was composed of tasks, don't attempt to recollect statistics self._collect_metrics(job, job_metrics_directory) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() if job.state == job.states.ERROR: self._report_error() elif task_wrapper: @@ -2340,8 +2331,7 @@ def setup_external_metadata( if output_dataset_assoc.dataset.ext == "auto": context = self.get_dataset_finish_context({}, output_dataset_assoc) output_dataset_assoc.dataset.extension = context.get("ext", "data") - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() if tmp_dir is None: # this dir should should relative to the exec_dir tmp_dir = self.app.config.new_file_path @@ -2583,8 +2573,7 @@ def set_container(self, container): container_info=container.container_info, ) self.sa_session.add(cont) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() class JobWrapper(MinimalJobWrapper): @@ -2631,8 +2620,7 @@ def set_job_destination(self, job_destination, external_id=None, flush=True, job job.job_runner_external_id = external_id self.sa_session.add(job) if flush: - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() class TaskWrapper(JobWrapper): @@ -2687,8 +2675,7 @@ def prepare(self, compute_environment=None): compute_environment = compute_environment or self.default_compute_environment(job) tool_evaluator.set_compute_environment(compute_environment) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() if not self.remote_command_line: ( @@ -2707,8 +2694,7 @@ def prepare(self, compute_environment=None): # if the server was stopped and restarted before the job finished task.command_line = self.command_line self.sa_session.add(task) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() self.status = "prepared" return self.extra_filenames @@ -2736,8 +2722,7 @@ def change_state(self, state, info=False, flush=True, job=None): task.info = info task.state = state self.sa_session.add(task) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def get_state(self): task = self.get_task() @@ -2756,8 +2741,7 @@ def set_runner(self, runner_url, external_id): task.task_runner_external_id = external_id # DBTODO Check task job_runner_stuff self.sa_session.add(task) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def finish(self, stdout, stderr, tool_exit_code=None, **kwds): # DBTODO integrate previous finish logic. @@ -2800,8 +2784,7 @@ def finish(self, stdout, stderr, tool_exit_code=None, **kwds): self._collect_metrics(task) task.exit_code = tool_exit_code task.command_line = self.command_line - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def cleanup(self, delete_files=True): # There is no task cleanup. The job cleans up for all tasks. diff --git a/lib/galaxy/jobs/handler.py b/lib/galaxy/jobs/handler.py index ef2fb7c98cef..eb9e41b67207 100644 --- a/lib/galaxy/jobs/handler.py +++ b/lib/galaxy/jobs/handler.py @@ -38,10 +38,7 @@ ) from galaxy.jobs.mapper import JobNotReadyException from galaxy.managers.jobs import get_jobs_to_check_at_startup -from galaxy.model.base import ( - check_database_connection, - transaction, -) +from galaxy.model.base import check_database_connection from galaxy.structured_app import MinimalManagerApp from galaxy.util import unicodify from galaxy.util.custom_logging import get_logger @@ -306,8 +303,7 @@ def __check_jobs_at_startup(self): self._check_job_at_startup(job) except Exception: log.exception("Error while recovering job %s during application startup.", job.id) - with transaction(session): - session.commit() + session.commit() def _check_job_at_startup(self, job: model.Job): assert job.tool_id is not None @@ -591,8 +587,7 @@ def __handle_waiting_jobs(self): for id in set(self.job_wrappers.keys()) - set(new_waiting_jobs): del self.job_wrappers[id] # Commit updated state - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def __filter_jobs_with_invalid_input_states(self, jobs): """ diff --git a/lib/galaxy/jobs/runners/__init__.py b/lib/galaxy/jobs/runners/__init__.py index e169e0b658b9..775498a9326e 100644 --- a/lib/galaxy/jobs/runners/__init__.py +++ b/lib/galaxy/jobs/runners/__init__.py @@ -41,10 +41,7 @@ job_script, write_script, ) -from galaxy.model.base import ( - check_database_connection, - transaction, -) +from galaxy.model.base import check_database_connection from galaxy.tool_util.deps.dependencies import ( JobInfo, ToolInfo, @@ -669,8 +666,7 @@ def _finish_or_resubmit_job(self, job_state: "JobState", job_stdout, job_stderr, # Flush with streams... self.sa_session.add(job) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() if not job_ok: job_runner_state = JobState.runner_states.TOOL_DETECT_ERROR diff --git a/lib/galaxy/jobs/runners/state_handlers/resubmit.py b/lib/galaxy/jobs/runners/state_handlers/resubmit.py index 172237a32f66..c722926e5374 100644 --- a/lib/galaxy/jobs/runners/state_handlers/resubmit.py +++ b/lib/galaxy/jobs/runners/state_handlers/resubmit.py @@ -3,7 +3,6 @@ from galaxy import model from galaxy.jobs.runners import JobState -from galaxy.model.base import transaction from ._safe_eval import safe_eval __all__ = ("failure",) @@ -84,8 +83,7 @@ def _handle_resubmit_definitions(resubmit_definitions, app, job_runner, job_stat job.set_handler(resubmit["handler"]) job_runner.sa_session.add(job) # Is this safe to do here? - with transaction(job_runner.sa_session): - job_runner.sa_session.commit() + job_runner.sa_session.commit() # Cache the destination to prevent rerunning dynamic after # resubmit job_state.job_wrapper.job_runner_mapper.cached_job_destination = new_destination diff --git a/lib/galaxy/jobs/runners/tasks.py b/lib/galaxy/jobs/runners/tasks.py index 3b2c0c00fba1..aadeb13e1b47 100644 --- a/lib/galaxy/jobs/runners/tasks.py +++ b/lib/galaxy/jobs/runners/tasks.py @@ -6,7 +6,6 @@ from galaxy import model from galaxy.jobs import TaskWrapper from galaxy.jobs.runners import BaseJobRunner -from galaxy.model.base import transaction log = logging.getLogger(__name__) @@ -49,8 +48,7 @@ def queue_job(self, job_wrapper): try: job_wrapper.change_state(model.Job.states.RUNNING) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() # Split with the defined method. parallelism = job_wrapper.get_parallelism() try: @@ -69,8 +67,7 @@ def queue_job(self, job_wrapper): task_wrappers = [] for task in tasks: self.sa_session.add(task) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() # Must flush prior to the creation and queueing of task wrappers. for task in tasks: tw = TaskWrapper(task, job_wrapper.queue) From 70aa1d668343b7d4ddd16258ff9046fa8fb972e6 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:09:04 -0500 Subject: [PATCH 23/39] Remove transaction helper from galaxy.web_stack --- lib/galaxy/web_stack/handlers.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/galaxy/web_stack/handlers.py b/lib/galaxy/web_stack/handlers.py index 8c401e3ab2bc..bd3376220f86 100644 --- a/lib/galaxy/web_stack/handlers.py +++ b/lib/galaxy/web_stack/handlers.py @@ -13,7 +13,6 @@ from sqlalchemy.orm import object_session from galaxy.exceptions import HandlerAssignmentError -from galaxy.model.base import transaction from galaxy.util import ( ExecutionTimer, listify, @@ -462,6 +461,5 @@ def assign_handler(self, obj, configured=None, **kwargs): def _timed_flush_obj(obj): obj_flush_timer = ExecutionTimer() sa_session = object_session(obj) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() log.info(f"Flushed transaction for {obj.log_str()} {obj_flush_timer}") From 2f604822e0a51ff35de6608070fdc1f023c2ae3d Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:11:56 -0500 Subject: [PATCH 24/39] Remove transaction helper from galaxy.webapps.base --- lib/galaxy/webapps/base/controller.py | 52 +++++++++------------------ lib/galaxy/webapps/base/webapp.py | 29 +++++---------- 2 files changed, 26 insertions(+), 55 deletions(-) diff --git a/lib/galaxy/webapps/base/controller.py b/lib/galaxy/webapps/base/controller.py index bc995f61409d..92bfc7d8f664 100644 --- a/lib/galaxy/webapps/base/controller.py +++ b/lib/galaxy/webapps/base/controller.py @@ -45,7 +45,6 @@ HistoryDatasetCollectionAssociation, LibraryDatasetDatasetAssociation, ) -from galaxy.model.base import transaction from galaxy.model.item_attrs import UsesAnnotations from galaxy.structured_app import BasicSharedApp from galaxy.util.dictifiable import Dictifiable @@ -512,8 +511,7 @@ def _copy_hda_to_library_folder( # If there is, refactor `ldda.visible = True` to do this only when adding HDCAs. ldda.visible = True ldda.update_parent_folder_update_times() - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() ldda_dict = ldda.to_dict() rval = trans.security.encode_dict_ids(ldda_dict) update_time = ldda.update_time.isoformat() @@ -599,8 +597,7 @@ def _apply_hda_permissions_to_ldda(self, trans, hda, ldda): flush_needed = True if flush_needed: - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # finally, apply the new library_dataset to its associated ldda (must be the same) security_agent.copy_library_permissions(trans, library_dataset, ldda) @@ -690,8 +687,7 @@ def unpack_bookmarks(bookmarks_json): vis.latest_revision = vis_rev session.add(vis_rev) - with transaction(session): - session.commit() + session.commit() encoded_id = trans.security.encode_id(vis.id) return {"vis_id": encoded_id, "url": url_for(controller="visualization", action=vis.type, id=encoded_id)} @@ -958,8 +954,7 @@ def get_stored_workflow(self, trans, id, check_ownership=True, check_accessible= # Older workflows may be missing slugs, so set them here. if not workflow.slug: self.slug_builder.create_item_slug(trans.sa_session, workflow) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return workflow @@ -987,8 +982,7 @@ def _import_shared_workflow(self, trans, stored: model.StoredWorkflow): # Save new workflow. session = trans.sa_session session.add(imported_stored) - with transaction(session): - session.commit() + session.commit() # Copy annotations. self.copy_item_annotation(session, stored.user, stored, imported_stored.user, imported_stored) @@ -996,8 +990,7 @@ def _import_shared_workflow(self, trans, stored: model.StoredWorkflow): self.copy_item_annotation( session, stored.user, step, imported_stored.user, imported_stored.latest_workflow.steps[order_index] ) - with transaction(session): - session.commit() + session.commit() return imported_stored def _workflow_to_dict(self, trans, stored): @@ -1045,8 +1038,7 @@ def save_widget_field(self, trans, field_obj, widget_name, **kwd): field_obj.country = util.restore_text(params.get(f"{widget_name}_country", "")) field_obj.phone = util.restore_text(params.get(f"{widget_name}_phone", "")) trans.sa_session.add(field_obj) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def get_form_values(self, trans, user, form_definition, **kwd): """ @@ -1101,8 +1093,7 @@ def set_slug_async(self, trans, id, new_slug): # Only update slug if slug is not already in use. if not slug_exists(trans.sa_session, item.__class__, item.user, new_slug): item.slug = new_slug - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return item.slug @@ -1153,16 +1144,14 @@ def _remove_items_tag(self, trans, item_class_name, id, tag_name): user = trans.user tagged_item = self._get_tagged_item(trans, item_class_name, id) deleted = tagged_item and trans.tag_handler.remove_item_tag(user, tagged_item, tag_name) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return deleted def _apply_item_tag(self, trans, item_class_name, id, tag_name, tag_value=None): user = trans.user tagged_item = self._get_tagged_item(trans, item_class_name, id) tag_assoc = trans.tag_handler.apply_item_tag(user, tagged_item, tag_name, tag_value) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return tag_assoc def _get_item_tag_assoc(self, trans, item_class_name, id, tag_name): @@ -1225,8 +1214,7 @@ def set_item_extended_metadata_obj(self, trans, item, extmeta_obj, check_writabl trans.get_current_user_roles(), item, trans.user ): item.extended_metadata = extmeta_obj - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if item.__class__ == HistoryDatasetAssociation: history = None if check_writable: @@ -1235,8 +1223,7 @@ def set_item_extended_metadata_obj(self, trans, item, extmeta_obj, check_writabl history = self.security_check(trans, item, check_ownership=False, check_accessible=True) if history: item.extended_metadata = extmeta_obj - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def unset_item_extended_metadata_obj(self, trans, item, check_writable=False): if item.__class__ == LibraryDatasetDatasetAssociation: @@ -1244,8 +1231,7 @@ def unset_item_extended_metadata_obj(self, trans, item, check_writable=False): trans.get_current_user_roles(), item, trans.user ): item.extended_metadata = None - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if item.__class__ == HistoryDatasetAssociation: history = None if check_writable: @@ -1254,8 +1240,7 @@ def unset_item_extended_metadata_obj(self, trans, item, check_writable=False): history = self.security_check(trans, item, check_ownership=False, check_accessible=True) if history: item.extended_metadata = None - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def create_extended_metadata(self, trans, extmeta): """ @@ -1264,20 +1249,17 @@ def create_extended_metadata(self, trans, extmeta): """ ex_meta = ExtendedMetadata(extmeta) trans.sa_session.add(ex_meta) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() for path, value in self._scan_json_block(extmeta): meta_i = ExtendedMetadataIndex(ex_meta, path, value) trans.sa_session.add(meta_i) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return ex_meta def delete_extended_metadata(self, trans, item): if item.__class__ == ExtendedMetadata: trans.sa_session.delete(item) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def _scan_json_block(self, meta, prefix=""): """ diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index 611f4fa02c9a..bff9b18d96fd 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -40,10 +40,7 @@ from galaxy.managers import context from galaxy.managers.session import GalaxySessionManager from galaxy.managers.users import UserManager -from galaxy.model.base import ( - ensure_object_added_to_session, - transaction, -) +from galaxy.model.base import ensure_object_added_to_session from galaxy.structured_app import ( BasicSharedApp, MinimalApp, @@ -375,8 +372,7 @@ def __init__( expiration_time = now self.galaxy_session.last_action = now - datetime.timedelta(seconds=1) self.sa_session.add(self.galaxy_session) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() if expiration_time < now: # Expiration time has passed. self.handle_user_logout() @@ -397,8 +393,7 @@ def __init__( else: self.galaxy_session.last_action = now self.sa_session.add(self.galaxy_session) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() @property def app(self): @@ -472,8 +467,7 @@ def set_user(self, user): if user and not user.bootstrap_admin_user: self.galaxy_session.user = user self.sa_session.add(self.galaxy_session) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() self.__user = user user = property(get_user, set_user) @@ -681,8 +675,7 @@ def _ensure_valid_session(self, session_cookie: str, create: bool = True) -> Non # be needed. if prev_galaxy_session: self.sa_session.add(prev_galaxy_session) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() def _ensure_logged_in_user(self, session_cookie: str) -> None: # The value of session_cookie can be one of @@ -854,8 +847,7 @@ def handle_user_login(self, user): else: cookie_name = "galaxycommunitysession" self.sa_session.add_all((prev_galaxy_session, self.galaxy_session)) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() # This method is not called from the Galaxy reports, so the cookie will always be galaxysession self.__update_session_cookie(name=cookie_name) @@ -881,8 +873,7 @@ def handle_user_logout(self, logout_all=False): for other_galaxy_session in self.sa_session.scalars(stmt): other_galaxy_session.is_valid = False self.sa_session.add(other_galaxy_session) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() if self.webapp.name == "galaxy": # This method is not called from the Galaxy reports, so the cookie will always be galaxysession self.__update_session_cookie(name="galaxysession") @@ -919,8 +910,7 @@ def set_history(self, history): if history and not history.deleted: self.galaxy_session.current_history = history self.sa_session.add(self.galaxy_session) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() @property def history(self): @@ -1002,8 +992,7 @@ def new_history(self, name=None): self.app.security_agent.history_set_default_permissions(history) # Save self.sa_session.add_all((self.galaxy_session, history)) - with transaction(self.sa_session): - self.sa_session.commit() + self.sa_session.commit() return history @base.lazy_property From 226e00d44d14cc178b9b56d4adc2005049e9b545 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:14:22 -0500 Subject: [PATCH 25/39] Remove transaction helper from galaxy.webapps.galaxy.api --- lib/galaxy/webapps/galaxy/api/annotations.py | 4 +-- lib/galaxy/webapps/galaxy/api/forms.py | 4 +-- .../webapps/galaxy/api/library_datasets.py | 7 ++--- lib/galaxy/webapps/galaxy/api/users.py | 31 ++++++------------- lib/galaxy/webapps/galaxy/api/workflows.py | 10 ++---- 5 files changed, 17 insertions(+), 39 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/annotations.py b/lib/galaxy/webapps/galaxy/api/annotations.py index 0fdce24cb0dd..db0787b5f342 100644 --- a/lib/galaxy/webapps/galaxy/api/annotations.py +++ b/lib/galaxy/webapps/galaxy/api/annotations.py @@ -10,7 +10,6 @@ managers, ) from galaxy.managers.context import ProvidesHistoryContext -from galaxy.model.base import transaction from galaxy.model.item_attrs import UsesAnnotations from galaxy.util.sanitize_html import sanitize_html from galaxy.web import expose_api @@ -43,8 +42,7 @@ def create(self, trans: ProvidesHistoryContext, payload: dict, **kwd): new_annotation = sanitize_html(new_annotation) self.add_item_annotation(trans.sa_session, trans.user, item, new_annotation) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return new_annotation return "" diff --git a/lib/galaxy/webapps/galaxy/api/forms.py b/lib/galaxy/webapps/galaxy/api/forms.py index 97c8bf2e6700..5abd811aa47e 100644 --- a/lib/galaxy/webapps/galaxy/api/forms.py +++ b/lib/galaxy/webapps/galaxy/api/forms.py @@ -11,7 +11,6 @@ from galaxy.managers.context import ProvidesUserContext from galaxy.managers.forms import FormManager from galaxy.model import FormDefinition -from galaxy.model.base import transaction from galaxy.schema.fields import DecodedDatabaseIdField from galaxy.util import XML from galaxy.webapps.base.controller import url_for @@ -105,8 +104,7 @@ def create(self, trans, payload, **kwd): # enhance to allow creating from more than just xml form_definition = form_factory.from_elem(XML(xml_text)) trans.sa_session.add(form_definition) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() encoded_id = trans.security.encode_id(form_definition.id) item = form_definition.to_dict( view="element", diff --git a/lib/galaxy/webapps/galaxy/api/library_datasets.py b/lib/galaxy/webapps/galaxy/api/library_datasets.py index 59d8065b85cd..28f10e9f3d94 100644 --- a/lib/galaxy/webapps/galaxy/api/library_datasets.py +++ b/lib/galaxy/webapps/galaxy/api/library_datasets.py @@ -26,7 +26,6 @@ library_datasets, roles, ) -from galaxy.model.base import transaction from galaxy.structured_app import StructuredApp from galaxy.tools.actions import upload_common from galaxy.tools.parameters import populate_state @@ -264,8 +263,7 @@ def update_permissions(self, trans, encoded_dataset_id, payload=None, **kwd): trans.app.security_agent.permitted_actions.DATASET_ACCESS.action, dataset, private_role ) trans.sa_session.add(dp) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if not trans.app.security_agent.dataset_is_private_to_user(trans, dataset): # Check again and inform the user if dataset is not private. raise exceptions.InternalServerError("An error occurred and the dataset is NOT private.") @@ -358,8 +356,7 @@ def delete(self, trans, encoded_dataset_id, **kwd): library_dataset.deleted = True trans.sa_session.add(library_dataset) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() rval = trans.security.encode_all_ids(library_dataset.to_dict()) nice_size = util.nice_size( diff --git a/lib/galaxy/webapps/galaxy/api/users.py b/lib/galaxy/webapps/galaxy/api/users.py index cea38b00bdf8..3b10c9668b01 100644 --- a/lib/galaxy/webapps/galaxy/api/users.py +++ b/lib/galaxy/webapps/galaxy/api/users.py @@ -41,7 +41,6 @@ UserObjectstoreUsage, UserQuotaUsage, ) -from galaxy.model.base import transaction from galaxy.schema import APIKeyModel from galaxy.schema.schema import ( AnonUserModel, @@ -376,8 +375,7 @@ def set_beacon( user = self.service.get_user(trans, user_id) user.preferences["beacon_enabled"] = payload.enabled - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return payload @@ -401,8 +399,7 @@ def remove_favorite( del favorite_tools[favorite_tools.index(object_id)] favorites["tools"] = favorite_tools user.preferences["favorites"] = json.dumps(favorites) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() else: raise exceptions.ObjectNotFound("Given object is not in the list of favorites") return FavoriteObjectsSummary.model_validate(favorites) @@ -433,8 +430,7 @@ def set_favorite( favorite_tools.append(tool_id) favorites["tools"] = favorite_tools user.preferences["favorites"] = json.dumps(favorites) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return FavoriteObjectsSummary.model_validate(favorites) @router.put( @@ -450,8 +446,7 @@ def set_theme( ) -> str: user = self.service.get_user(trans, user_id) user.preferences["theme"] = theme - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return theme @router.put( @@ -496,8 +491,7 @@ def add_custom_builds( trans.app.object_store.create(new_len.dataset) except ObjectInvalid: raise exceptions.InternalServerError("Unable to create output dataset: object store is full.") - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() counter = 0 lines_skipped = 0 with open(new_len.get_file_name(), "w") as f: @@ -537,8 +531,7 @@ def add_custom_builds( raise exceptions.ToolExecutionError("Failed to convert dataset.") dbkeys[key] = build_dict user.preferences["dbkeys"] = json.dumps(dbkeys) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return Response(status_code=status.HTTP_204_NO_CONTENT) @router.get( @@ -589,8 +582,7 @@ def delete_custom_builds( if key and key in dbkeys: del dbkeys[key] user.preferences["dbkeys"] = json.dumps(dbkeys) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return DeletedCustomBuild(message=f"Deleted {key}.") else: raise exceptions.ObjectNotFound(f"Could not find and delete build ({key}).") @@ -958,8 +950,7 @@ def set_information(self, trans, id, payload=None, **kwd): user.email = email trans.sa_session.add(user) trans.sa_session.add(private_role) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if trans.app.config.user_activation_on: # Deactivate the user if email was changed and activation is on. user.active = False @@ -1048,8 +1039,7 @@ def set_information(self, trans, id, payload=None, **kwd): user.addresses.append(user_address) trans.sa_session.add(user_address) trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() trans.log_event("User information added") return {"message": "User information has been saved."} @@ -1164,8 +1154,7 @@ def set_toolbox_filters(self, trans, id, payload=None, **kwd): new_filters.append(prefixed_name[len(prefix) :]) user.preferences[filter_type] = ",".join(new_filters) trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return {"message": "Toolbox filters have been saved."} def _add_filter_inputs(self, factory, filter_types, inputs, errors, filter_type, saved_values): diff --git a/lib/galaxy/webapps/galaxy/api/workflows.py b/lib/galaxy/webapps/galaxy/api/workflows.py index b52d495d40e6..db2ebb64f00c 100644 --- a/lib/galaxy/webapps/galaxy/api/workflows.py +++ b/lib/galaxy/webapps/galaxy/api/workflows.py @@ -50,7 +50,6 @@ WorkflowCreateOptions, WorkflowUpdateOptions, ) -from galaxy.model.base import transaction from galaxy.model.item_attrs import UsesAnnotations from galaxy.schema.fields import DecodedDatabaseIdField from galaxy.schema.invocation import ( @@ -187,8 +186,7 @@ def set_workflow_menu(self, trans: GalaxyWebTransaction, payload=None, **kwd): m.stored_workflow = session.get(model.StoredWorkflow, wf_id) user.stored_workflow_menu_entries.append(m) - with transaction(session): - session.commit() + session.commit() message = "Menu updated." trans.set_message(message) return {"message": message, "status": "done"} @@ -497,8 +495,7 @@ def update(self, trans: GalaxyWebTransaction, id, payload, **kwds): ) if require_flush: - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if "steps" in workflow_dict or "comments" in workflow_dict: try: @@ -687,8 +684,7 @@ def _workflow_from_dict(self, trans, data, workflow_create_options, source=None) ) if importable: self._make_item_accessible(trans.sa_session, created_workflow.stored_workflow) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() self._import_tools_if_needed(trans, workflow_create_options, raw_workflow_description) return created_workflow.stored_workflow, created_workflow.missing_tools From c995c362d4f60e44b674b481450ac1ece8639bd3 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:47:44 -0500 Subject: [PATCH 26/39] Remove transaction helper from galaxy.webapps.galaxy.services --- lib/galaxy/webapps/galaxy/services/datasets.py | 4 +--- lib/galaxy/webapps/galaxy/services/histories.py | 10 +++------- .../webapps/galaxy/services/history_contents.py | 16 +++++----------- .../webapps/galaxy/services/library_contents.py | 13 ++++--------- lib/galaxy/webapps/galaxy/services/pages.py | 7 ++----- lib/galaxy/webapps/galaxy/services/tools.py | 4 +--- .../webapps/galaxy/services/visualizations.py | 16 +++++----------- lib/galaxy/webapps/galaxy/services/workflows.py | 4 +--- 8 files changed, 22 insertions(+), 52 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/services/datasets.py b/lib/galaxy/webapps/galaxy/services/datasets.py index 20c22a720591..b1a509f8d5af 100644 --- a/lib/galaxy/webapps/galaxy/services/datasets.py +++ b/lib/galaxy/webapps/galaxy/services/datasets.py @@ -47,7 +47,6 @@ HistoryContentsManager, ) from galaxy.managers.lddas import LDDAManager -from galaxy.model.base import transaction from galaxy.objectstore.badges import BadgeDict from galaxy.schema import ( FilterQueryParams, @@ -764,8 +763,7 @@ def delete_batch( ) if success_count: - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return DeleteDatasetBatchResult.model_construct(success_count=success_count, errors=errors) def get_structured_content( diff --git a/lib/galaxy/webapps/galaxy/services/histories.py b/lib/galaxy/webapps/galaxy/services/histories.py index 1746130ffd70..ff63b42af83d 100644 --- a/lib/galaxy/webapps/galaxy/services/histories.py +++ b/lib/galaxy/webapps/galaxy/services/histories.py @@ -42,7 +42,6 @@ ) from galaxy.managers.users import UserManager from galaxy.model import HistoryDatasetAssociation -from galaxy.model.base import transaction from galaxy.model.scoped_session import galaxy_scoped_session from galaxy.model.store import payload_to_source_uri from galaxy.schema import ( @@ -288,8 +287,7 @@ def create( trans.app.security_agent.history_set_default_permissions(new_history) trans.sa_session.add(new_history) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # an anonymous user can only have one history if self.user_manager.is_anonymous(trans.user): @@ -387,8 +385,7 @@ def prepare_download( result = prepare_history_download.delay(request=request, task_user_id=getattr(trans.user, "id", None)) task_summary = async_task_summary(result) export_association.task_uuid = task_summary.id - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return AsyncFile(storage_request_id=short_term_storage_target.request_id, task=task_summary) def write_store( @@ -405,8 +402,7 @@ def write_store( result = write_history_to.delay(request=request, task_user_id=getattr(trans.user, "id", None)) task_summary = async_task_summary(result) export_association.task_uuid = task_summary.id - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return task_summary def update( diff --git a/lib/galaxy/webapps/galaxy/services/history_contents.py b/lib/galaxy/webapps/galaxy/services/history_contents.py index 6e60c334753a..ba9920f854a6 100644 --- a/lib/galaxy/webapps/galaxy/services/history_contents.py +++ b/lib/galaxy/webapps/galaxy/services/history_contents.py @@ -65,7 +65,6 @@ LibraryDataset, User, ) -from galaxy.model.base import transaction from galaxy.model.security import GalaxyRBACAgent from galaxy.objectstore import BaseObjectStore from galaxy.schema import ( @@ -710,8 +709,7 @@ def bulk_operation( filters, ) errors = self._apply_bulk_operation(contents, payload.operation, payload.params, trans) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() success_count = len(contents) - len(errors) return HistoryContentBulkOperationResult(success_count=success_count, errors=errors) @@ -1179,8 +1177,7 @@ def traverse(folder): ] history.add_pending_items() - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() for hda in hdas: hda_dict = self.hda_serializer.serialize_to_view( @@ -1216,8 +1213,7 @@ def __create_dataset( if hda is None: return None - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return self.hda_serializer.serialize_to_view( hda, user=trans.user, trans=trans, encode_id=False, **serialization_params.model_dump() ) @@ -1476,8 +1472,7 @@ def _change_datatype( ): if isinstance(item, HistoryDatasetAssociation): wrapped_task = self._change_item_datatype(item, params, trans) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if wrapped_task: wrapped_task.delay() @@ -1487,8 +1482,7 @@ def _change_datatype( wrapped_task = self._change_item_datatype(dataset_instance, params, trans) if wrapped_task: wrapped_tasks.append(wrapped_task) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # chain these for sequential execution. chord would be nice, but requires a non-RPC backend. chain( *wrapped_tasks, diff --git a/lib/galaxy/webapps/galaxy/services/library_contents.py b/lib/galaxy/webapps/galaxy/services/library_contents.py index ee94caa1fba2..eec1174ab4c7 100644 --- a/lib/galaxy/webapps/galaxy/services/library_contents.py +++ b/lib/galaxy/webapps/galaxy/services/library_contents.py @@ -25,7 +25,6 @@ Library, tags, ) -from galaxy.model.base import transaction from galaxy.schema.fields import DecodedDatabaseIdField from galaxy.schema.library_contents import ( AnyLibraryContentsCreatePayload, @@ -197,8 +196,7 @@ def update( metadata_safe=True, ) trans.sa_session.add(assoc) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def delete( self, @@ -218,8 +216,7 @@ def delete( if payload.purge: ld.purged = True trans.sa_session.add(ld) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # TODO: had to change this up a bit from Dataset.user_can_purge dataset = ld.library_dataset_dataset_association.dataset @@ -234,11 +231,9 @@ def delete( except Exception: pass # flush now to preserve deleted state in case of later interruption - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() rval["purged"] = True - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() rval["deleted"] = True return LibraryContentsDeleteResponse(**rval) diff --git a/lib/galaxy/webapps/galaxy/services/pages.py b/lib/galaxy/webapps/galaxy/services/pages.py index a5bafa99d5d7..197b77566e2d 100644 --- a/lib/galaxy/webapps/galaxy/services/pages.py +++ b/lib/galaxy/webapps/galaxy/services/pages.py @@ -12,7 +12,6 @@ PageManager, PageSerializer, ) -from galaxy.model.base import transaction from galaxy.schema import PdfDocumentType from galaxy.schema.fields import DecodedDatabaseIdField from galaxy.schema.schema import ( @@ -97,8 +96,7 @@ def delete(self, trans, id: DecodedDatabaseIdField): page = base.get_object(trans, id, "Page", check_ownership=True) page.deleted = True - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def undelete(self, trans, id: DecodedDatabaseIdField): """ @@ -109,8 +107,7 @@ def undelete(self, trans, id: DecodedDatabaseIdField): page = base.get_object(trans, id, "Page", check_ownership=True) page.deleted = False - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() def show(self, trans, id: DecodedDatabaseIdField) -> PageDetails: """View a page summary and the content of the latest revision diff --git a/lib/galaxy/webapps/galaxy/services/tools.py b/lib/galaxy/webapps/galaxy/services/tools.py index 6897965d112f..29c87a24eee8 100644 --- a/lib/galaxy/webapps/galaxy/services/tools.py +++ b/lib/galaxy/webapps/galaxy/services/tools.py @@ -27,7 +27,6 @@ LibraryDatasetDatasetAssociation, PostJobAction, ) -from galaxy.model.base import transaction from galaxy.schema.fetch_data import ( FetchDataFormPayload, FetchDataPayload, @@ -191,8 +190,7 @@ def _create(self, trans: ProvidesHistoryContext, payload, **kwd): new_pja_flush = True if new_pja_flush: - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return self._handle_inputs_output_to_api_response(trans, tool, target_history, vars) diff --git a/lib/galaxy/webapps/galaxy/services/visualizations.py b/lib/galaxy/webapps/galaxy/services/visualizations.py index d2b7e6819519..d9721d979207 100644 --- a/lib/galaxy/webapps/galaxy/services/visualizations.py +++ b/lib/galaxy/webapps/galaxy/services/visualizations.py @@ -22,7 +22,6 @@ Visualization, VisualizationRevision, ) -from galaxy.model.base import transaction from galaxy.model.item_attrs import ( add_item_annotation, get_item_annotation_str, @@ -175,8 +174,7 @@ def create( session = trans.sa_session session.add(revision) - with transaction(session): - session.commit() + session.commit() return VisualizationCreateResponse(id=str(visualization.id)) @@ -221,8 +219,7 @@ def update( # allow updating vis title visualization.title = title visualization.deleted = deleted - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return VisualizationUpdateResponse(**rval) if rval else None @@ -280,8 +277,7 @@ def _add_visualization_revision( visualization.latest_revision = revision # TODO:?? does this automatically add revision to visualzation.revisions? trans.sa_session.add(revision) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return revision def _create_visualization( @@ -323,8 +319,7 @@ def _create_visualization( session = trans.sa_session session.add(visualization) - with transaction(session): - session.commit() + session.commit() return visualization @@ -359,6 +354,5 @@ def _import_visualization( # TODO: need to handle custom db keys. imported_visualization = visualization.copy(user=user, title=f"imported: {visualization.title}") trans.sa_session.add(imported_visualization) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return imported_visualization diff --git a/lib/galaxy/webapps/galaxy/services/workflows.py b/lib/galaxy/webapps/galaxy/services/workflows.py index f34ce0db46b2..bc45cd26d9cb 100644 --- a/lib/galaxy/webapps/galaxy/services/workflows.py +++ b/lib/galaxy/webapps/galaxy/services/workflows.py @@ -20,7 +20,6 @@ WorkflowsManager, ) from galaxy.model import StoredWorkflow -from galaxy.model.base import transaction from galaxy.schema.invocation import WorkflowInvocationResponse from galaxy.schema.schema import ( InvocationsStateCounts, @@ -175,8 +174,7 @@ def invoke_workflow( ) invocations.append(workflow_invocation) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() encoded_invocations = [WorkflowInvocationResponse(**invocation.to_dict()) for invocation in invocations] if is_batch: return encoded_invocations From 17ebf870190fb71e4f9ada1785b8b992bb9f240a Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:50:06 -0500 Subject: [PATCH 27/39] Remove transaction helper from galaxy.webapps.galaxy.controllers --- lib/galaxy/webapps/galaxy/controllers/admin.py | 16 +++++----------- .../webapps/galaxy/controllers/admin_toolshed.py | 4 +--- lib/galaxy/webapps/galaxy/controllers/async.py | 10 +++------- lib/galaxy/webapps/galaxy/controllers/dataset.py | 13 ++++--------- lib/galaxy/webapps/galaxy/controllers/forms.py | 4 +--- lib/galaxy/webapps/galaxy/controllers/history.py | 7 ++----- lib/galaxy/webapps/galaxy/controllers/page.py | 4 +--- lib/galaxy/webapps/galaxy/controllers/tag.py | 7 ++----- .../webapps/galaxy/controllers/visualization.py | 10 +++------- 9 files changed, 22 insertions(+), 53 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/controllers/admin.py b/lib/galaxy/webapps/galaxy/controllers/admin.py index 2ea9e1a339c1..5b77cb9f7b80 100644 --- a/lib/galaxy/webapps/galaxy/controllers/admin.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin.py @@ -18,7 +18,6 @@ RequestParameterInvalidException, ) from galaxy.managers.quotas import QuotaManager -from galaxy.model.base import transaction from galaxy.model.index_filter_util import ( raw_text_column_filter, text_column_filter, @@ -726,8 +725,7 @@ def create_role(self, trans, payload=None, **kwd): num_in_groups = len(in_groups) + 1 else: num_in_groups = len(in_groups) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = f"Role '{role.name}' has been created with {len(in_users)} associated users and {num_in_groups} associated groups." if auto_create_checked: message += ( @@ -767,8 +765,7 @@ def rename_role(self, trans, payload=None, **kwd): role.name = new_name role.description = new_description trans.sa_session.add(role) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return {"message": f"Role '{old_name}' has been renamed to '{new_name}'."} @web.legacy_expose_api @@ -853,8 +850,7 @@ def rename_group(self, trans, payload=None, **kwd): if not (group.name == new_name): group.name = new_name trans.sa_session.add(group) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return {"message": f"Group '{old_name}' has been renamed to '{new_name}'."} @web.legacy_expose_api @@ -988,8 +984,7 @@ def create_group(self, trans, payload=None, **kwd): num_in_roles = len(in_roles) + 1 else: num_in_roles = len(in_roles) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = f"Group '{group.name}' has been created with {len(in_users)} associated users and {num_in_roles} associated roles." if auto_create_checked: message += ( @@ -1025,8 +1020,7 @@ def reset_user_password(self, trans, payload=None, **kwd): for user in users.values(): user.set_password_cleartext(password) trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return {"message": f"Passwords reset for {len(users)} user(s)."} else: return self.message_exception(trans, "Please specify user ids.") diff --git a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py index 81b6642e4ee4..c3ad846d83cf 100644 --- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py @@ -8,7 +8,6 @@ web, ) from galaxy.exceptions import ConfigDoesNotAllowException -from galaxy.model.base import transaction from galaxy.tool_shed.util import dependency_display from galaxy.tool_shed.util.repository_util import ( get_absolute_path_to_file_in_repository, @@ -150,7 +149,6 @@ def _manage_repository_json(self, trans, **kwd): if description != repository.description: repository.description = description trans.install_model.context.add(repository) - with transaction(trans.install_model.context): - trans.install_model.context.commit() + trans.install_model.context.commit() message = "The repository information has been updated." return dependency_display.build_manage_repository_dict(trans.app, status, repository) diff --git a/lib/galaxy/webapps/galaxy/controllers/async.py b/lib/galaxy/webapps/galaxy/controllers/async.py index 8ed26bf95603..e3b968fa0691 100644 --- a/lib/galaxy/webapps/galaxy/controllers/async.py +++ b/lib/galaxy/webapps/galaxy/controllers/async.py @@ -6,7 +6,6 @@ from urllib.parse import urlencode from galaxy import web -from galaxy.model.base import transaction from galaxy.util import ( DEFAULT_SOCKET_TIMEOUT, Params, @@ -128,8 +127,7 @@ def index(self, trans, tool_id=None, data_secret=None, **kwd): data.state = data.blurb = "error" data.info = f"Error -> {STATUS}" - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return f"Data {data_id} with status {STATUS} received. OK" else: @@ -199,8 +197,7 @@ def index(self, trans, tool_id=None, data_secret=None, **kwd): data.state = data.states.NEW trans.history.add_dataset(data, genome_build=GALAXY_BUILD) trans.sa_session.add(trans.history) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Need to explicitly create the file data.dataset.object_store.create(data.dataset) trans.log_event(f"Added dataset {data.id} to history {trans.history.id}", tool_id=tool_id) @@ -229,7 +226,6 @@ def index(self, trans, tool_id=None, data_secret=None, **kwd): data.info = unicodify(e) data.state = data.blurb = data.states.ERROR - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return trans.fill_template("root/tool_runner.mako", out_data={}, num_jobs=1, job_errors=[]) diff --git a/lib/galaxy/webapps/galaxy/controllers/dataset.py b/lib/galaxy/webapps/galaxy/controllers/dataset.py index 4be64e58b4e0..927f885186dc 100644 --- a/lib/galaxy/webapps/galaxy/controllers/dataset.py +++ b/lib/galaxy/webapps/galaxy/controllers/dataset.py @@ -29,7 +29,6 @@ HDAManager, ) from galaxy.managers.histories import HistoryManager -from galaxy.model.base import transaction from galaxy.model.item_attrs import ( UsesAnnotations, UsesItemRatings, @@ -347,8 +346,7 @@ def set_edit(self, trans, payload=None, **kwd): else: message = "Attributes updated, but metadata could not be changed because this dataset is currently being used as input or output. You must cancel or wait for these jobs to complete before changing metadata." status = "warning" - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() elif operation == "datatype": # The user clicked the Save button on the 'Change data type' form datatype = payload.get("datatype") @@ -366,8 +364,7 @@ def set_edit(self, trans, payload=None, **kwd): path = data.dataset.get_file_name() datatype = guess_ext(path, trans.app.datatypes_registry.sniff_order) trans.app.datatypes_registry.change_datatype(data, datatype) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() job, *_ = trans.app.datatypes_registry.set_external_metadata_tool.tool_action.execute( trans.app.datatypes_registry.set_external_metadata_tool, trans, @@ -712,8 +709,7 @@ def copy_datasets( new_history.name = new_history_name new_history.user = user trans.sa_session.add(new_history) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() target_history_ids.append(new_history.id) if user: target_histories = [ @@ -753,8 +749,7 @@ def copy_datasets( copy.copy_tags_from(user, content) for hist in target_histories: hist.add_pending_items() - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if current_history in target_histories: refresh_frames = ["history"] hist_names_str = ", ".join( diff --git a/lib/galaxy/webapps/galaxy/controllers/forms.py b/lib/galaxy/webapps/galaxy/controllers/forms.py index 251b8efee5a4..11d5b2ed19d5 100644 --- a/lib/galaxy/webapps/galaxy/controllers/forms.py +++ b/lib/galaxy/webapps/galaxy/controllers/forms.py @@ -10,7 +10,6 @@ from galaxy import model from galaxy.managers.forms import get_form -from galaxy.model.base import transaction from galaxy.model.index_filter_util import ( raw_text_column_filter, text_column_filter, @@ -292,6 +291,5 @@ def save_form_definition(self, trans, form_id=None, payload=None, **kwd): form_definition.form_definition_current = form_definition_current form_definition_current.latest_form = form_definition trans.sa_session.add(form_definition_current) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return form_definition, None diff --git a/lib/galaxy/webapps/galaxy/controllers/history.py b/lib/galaxy/webapps/galaxy/controllers/history.py index 56afb50cda4e..5ed3d4d149f5 100644 --- a/lib/galaxy/webapps/galaxy/controllers/history.py +++ b/lib/galaxy/webapps/galaxy/controllers/history.py @@ -11,7 +11,6 @@ from galaxy.managers import histories from galaxy.managers.sharable import SlugBuilder from galaxy.model import Role -from galaxy.model.base import transaction from galaxy.model.item_attrs import ( UsesAnnotations, UsesItemRatings, @@ -219,8 +218,7 @@ def purge_deleted_datasets(self, trans): hda.purged = True trans.sa_session.add(hda) trans.log_event(f"HDA id {hda.id} has been purged") - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if hda.dataset.user_can_purge: try: hda.dataset.full_delete() @@ -284,8 +282,7 @@ def rename(self, trans, payload=None, **kwd): elif new_name != cur_name: h.name = new_name trans.sa_session.add(h) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() trans.log_event(f"History renamed: id: {str(h.id)}, renamed to: {new_name}") messages.append(f"History '{cur_name}' renamed to '{new_name}'.") message = sanitize_text(" ".join(messages)) if messages else "History names remain unchanged." diff --git a/lib/galaxy/webapps/galaxy/controllers/page.py b/lib/galaxy/webapps/galaxy/controllers/page.py index fac24d92648d..ec4ff9ca9ca7 100644 --- a/lib/galaxy/webapps/galaxy/controllers/page.py +++ b/lib/galaxy/webapps/galaxy/controllers/page.py @@ -14,7 +14,6 @@ ) from galaxy.managers.sharable import SlugBuilder from galaxy.managers.workflows import WorkflowsManager -from galaxy.model.base import transaction from galaxy.model.db.user import get_user_by_username from galaxy.model.item_attrs import UsesItemRatings from galaxy.schema.schema import CreatePagePayload @@ -157,8 +156,7 @@ def edit(self, trans, payload=None, **kwd): p_annotation = sanitize_html(p_annotation) self.add_item_annotation(trans.sa_session, user, p, p_annotation) trans.sa_session.add(p) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return {"message": f"Attributes of '{p.title}' successfully saved.", "status": "success"} @web.expose diff --git a/lib/galaxy/webapps/galaxy/controllers/tag.py b/lib/galaxy/webapps/galaxy/controllers/tag.py index 3eb9f0fd612e..8515d4dfbcfa 100644 --- a/lib/galaxy/webapps/galaxy/controllers/tag.py +++ b/lib/galaxy/webapps/galaxy/controllers/tag.py @@ -12,7 +12,6 @@ ) from galaxy import web -from galaxy.model.base import transaction from galaxy.webapps.base.controller import ( BaseUIController, UsesTagsMixin, @@ -32,8 +31,7 @@ def add_tag_async(self, trans, item_id=None, item_class=None, new_tag=None, cont item = self._get_item(trans, item_class, trans.security.decode_id(item_id)) user = trans.user trans.tag_handler.apply_item_tags(user, item, new_tag) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Log. params = dict(item_id=item.id, item_class=item_class, tag=new_tag) trans.log_action(user, "tag", context, params) @@ -48,8 +46,7 @@ def remove_tag_async(self, trans, item_id=None, item_class=None, tag_name=None, item = self._get_item(trans, item_class, trans.security.decode_id(item_id)) user = trans.user trans.tag_handler.remove_item_tag(user, item, tag_name) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Log. params = dict(item_id=item.id, item_class=item_class, tag=tag_name) trans.log_action(user, "untag", context, params) diff --git a/lib/galaxy/webapps/galaxy/controllers/visualization.py b/lib/galaxy/webapps/galaxy/controllers/visualization.py index f39167a84253..ff796cf1c815 100644 --- a/lib/galaxy/webapps/galaxy/controllers/visualization.py +++ b/lib/galaxy/webapps/galaxy/controllers/visualization.py @@ -14,7 +14,6 @@ from galaxy.exceptions import MessageException from galaxy.managers.hdas import HDAManager from galaxy.managers.sharable import SlugBuilder -from galaxy.model.base import transaction from galaxy.model.item_attrs import ( UsesAnnotations, UsesItemRatings, @@ -70,8 +69,7 @@ def copy(self, trans, id, **kwargs): # Persist session = trans.sa_session session.add(copied_viz) - with transaction(session): - session.commit() + session.commit() # Display the management page trans.set_message(f'Created new visualization with name "{copied_viz.title}"') @@ -110,8 +108,7 @@ def imp(self, trans, id, **kwargs): # Persist session = trans.sa_session session.add(imported_visualization) - with transaction(session): - session.commit() + session.commit() # Redirect to load galaxy frames. return trans.show_ok_message( @@ -232,8 +229,7 @@ def edit(self, trans, payload=None, **kwd): v_annotation = sanitize_html(v_annotation) self.add_item_annotation(trans.sa_session, trans_user, v, v_annotation) trans.sa_session.add(v) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return {"message": f"Attributes of '{v.title}' successfully saved.", "status": "success"} # ------------------------- registry. From 5b797245ca69bb97e328168c8e695439f4e83bdb Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:53:58 -0500 Subject: [PATCH 28/39] Remove transaction helper from galaxy.tool_shed --- .../tool_shed/galaxy_install/install_manager.py | 10 +++------- .../galaxy_install/installed_repository_manager.py | 13 ++++--------- .../installed_repository_metadata_manager.py | 4 +--- .../repository_dependency_manager.py | 10 +++------- .../galaxy_install/tools/tool_panel_manager.py | 4 +--- .../galaxy_install/update_repository_manager.py | 10 +++------- lib/galaxy/tool_shed/util/repository_util.py | 14 ++++---------- lib/galaxy/tool_shed/util/shed_util_common.py | 4 +--- lib/galaxy/tool_shed/util/tool_dependency_util.py | 4 +--- 9 files changed, 21 insertions(+), 52 deletions(-) diff --git a/lib/galaxy/tool_shed/galaxy_install/install_manager.py b/lib/galaxy/tool_shed/galaxy_install/install_manager.py index 9c45ea79e7fc..1008044acee2 100644 --- a/lib/galaxy/tool_shed/galaxy_install/install_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/install_manager.py @@ -15,7 +15,6 @@ exceptions, util, ) -from galaxy.model.base import transaction from galaxy.tool_shed.galaxy_install.client import InstallationTarget from galaxy.tool_shed.galaxy_install.metadata.installed_repository_metadata_manager import ( InstalledRepositoryMetadataManager, @@ -172,8 +171,7 @@ def __handle_repository_contents( session = self.install_model.context session.add(tool_shed_repository) - with transaction(session): - session.commit() + session.commit() if "sample_files" in irmm_metadata_dict: sample_files = irmm_metadata_dict.get("sample_files", []) @@ -565,8 +563,7 @@ def install_tool_shed_repository( tool_panel_section_mapping = tool_panel_section_mapping or {} session = self.app.install_model.context - with transaction(session): - session.commit() + session.commit() if tool_panel_section_key: _, tool_section = self.app.toolbox.get_section(tool_panel_section_key) @@ -865,8 +862,7 @@ def update_tool_shed_repository_status(self, tool_shed_repository, status, error session = self.install_model.context session.add(tool_shed_repository) - with transaction(session): - session.commit() + session.commit() class RepositoriesInstalledException(exceptions.RequestParameterInvalidException): diff --git a/lib/galaxy/tool_shed/galaxy_install/installed_repository_manager.py b/lib/galaxy/tool_shed/galaxy_install/installed_repository_manager.py index 792b07abc386..8c608e5513c0 100644 --- a/lib/galaxy/tool_shed/galaxy_install/installed_repository_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/installed_repository_manager.py @@ -16,7 +16,6 @@ ) from galaxy import util -from galaxy.model.base import transaction from galaxy.model.tool_shed_install import ( ToolDependency, ToolShedRepository, @@ -146,8 +145,7 @@ def activate_repository(self, repository: ToolShedRepository) -> None: repository_tools_tups, ) self.context.add(repository) - with transaction(self.context): - self.context.commit() + self.context.commit() def add_entry_to_installed_repository_dependencies_of_installed_repositories( self, repository: ToolShedRepository @@ -704,8 +702,7 @@ def uninstall_repository(self, repository: ToolShedRepository, remove_from_disk= else: repository.status = ToolShedRepository.installation_status.DEACTIVATED self.context.add(repository) - with transaction(self.context): - self.context.commit() + self.context.commit() return errors def remove_entry_from_installed_repository_dependencies_of_installed_repositories( @@ -893,8 +890,7 @@ def _update_existing_tool_dependency( tool_dependency.status = ToolDependency.installation_status.UNINSTALLED tool_dependency.error_message = None context.add(tool_dependency) - with transaction(context): - context.commit() + context.commit() new_tool_dependency = tool_dependency else: # We have no new tool dependency definition based on a matching dependency name, so remove @@ -906,6 +902,5 @@ def _update_existing_tool_dependency( tool_dependency.name, ) context.delete(tool_dependency) - with transaction(context): - context.commit() + context.commit() return new_tool_dependency diff --git a/lib/galaxy/tool_shed/galaxy_install/metadata/installed_repository_metadata_manager.py b/lib/galaxy/tool_shed/galaxy_install/metadata/installed_repository_metadata_manager.py index 7bf7cc32ae69..60c4915a851a 100644 --- a/lib/galaxy/tool_shed/galaxy_install/metadata/installed_repository_metadata_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/metadata/installed_repository_metadata_manager.py @@ -9,7 +9,6 @@ from sqlalchemy import false from galaxy import util -from galaxy.model.base import transaction from galaxy.model.tool_shed_install import ToolShedRepository from galaxy.tool_shed.galaxy_install.client import InstallationTarget from galaxy.tool_shed.galaxy_install.tools import tool_panel_manager @@ -135,8 +134,7 @@ def reset_all_metadata_on_installed_repository(self): session = self.app.install_model.context session.add(self.repository) - with transaction(session): - session.commit() + session.commit() log.debug(f"Metadata has been reset on repository {self.repository.name}.") else: diff --git a/lib/galaxy/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py b/lib/galaxy/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py index 73b8863ab985..812fbb1d00b3 100644 --- a/lib/galaxy/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py @@ -17,7 +17,6 @@ urlopen, ) -from galaxy.model.base import transaction from galaxy.tool_shed.galaxy_install.tools import tool_panel_manager from galaxy.tool_shed.util import repository_util from galaxy.tool_shed.util.container_util import get_components_from_key @@ -141,8 +140,7 @@ def build_repository_dependency_relationships(self, repo_info_dicts, tool_shed_r ) session = install_model.context session.add(repository_dependency) - with transaction(session): - session.commit() + session.commit() # Build the relationship between the d_repository and the required_repository. rrda = install_model.RepositoryRepositoryDependencyAssociation( @@ -151,8 +149,7 @@ def build_repository_dependency_relationships(self, repo_info_dicts, tool_shed_r ) session = install_model.context session.add(rrda) - with transaction(session): - session.commit() + session.commit() def create_repository_dependency_objects( self, @@ -586,8 +583,7 @@ def reset_previously_installed_repository(self, repository): session = self.app.install_model.context session.add(repository) - with transaction(session): - session.commit() + session.commit() def _urlopen(url, data=None): diff --git a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py index 1539590b3ee9..843b8eafb956 100644 --- a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py @@ -7,7 +7,6 @@ ) from galaxy.exceptions import RequestParameterInvalidException -from galaxy.model.base import transaction from galaxy.tool_shed.galaxy_install.client import InstallationTarget from galaxy.tool_shed.util.basic_util import strip_path from galaxy.tool_shed.util.repository_util import get_repository_owner @@ -515,8 +514,7 @@ def remove_repository_contents(self, repository, shed_tool_conf, uninstall): session = self.app.install_model.context session.add(repository) - with transaction(session): - session.commit() + session.commit() # Create a list of guids for all tools that will be removed from the in-memory tool panel # and config file on disk. diff --git a/lib/galaxy/tool_shed/galaxy_install/update_repository_manager.py b/lib/galaxy/tool_shed/galaxy_install/update_repository_manager.py index dfa8bec8b769..f579c6ad205f 100644 --- a/lib/galaxy/tool_shed/galaxy_install/update_repository_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/update_repository_manager.py @@ -9,7 +9,6 @@ from sqlalchemy import false from galaxy import util -from galaxy.model.base import transaction from galaxy.model.tool_shed_install import ToolShedRepository from galaxy.tool_shed.util.repository_util import get_tool_shed_status_for_installed_repository from galaxy.tool_shed.util.shed_util_common import clean_dependency_relationships @@ -81,15 +80,13 @@ def __restarter(self) -> None: if tool_shed_status_dict: if tool_shed_status_dict != repository.tool_shed_status: repository.tool_shed_status = tool_shed_status_dict - with transaction(self.context): - self.context.commit() + self.context.commit() else: # The received tool_shed_status_dict is an empty dictionary, so coerce to None. tool_shed_status_dict = None if tool_shed_status_dict != repository.tool_shed_status: repository.tool_shed_status = tool_shed_status_dict - with transaction(self.context): - self.context.commit() + self.context.commit() self.sleeper.sleep(self.seconds_to_sleep) log.info("Update repository manager restarter shutting down...") @@ -119,7 +116,6 @@ def update_repository_record( repository.tool_shed_status = None # type:ignore[assignment] session = self.app.install_model.context session.add(repository) - with transaction(session): - session.commit() + session.commit() session.refresh(repository) return repository diff --git a/lib/galaxy/tool_shed/util/repository_util.py b/lib/galaxy/tool_shed/util/repository_util.py index 1a06be79c7dd..5f9a4cd0ff7b 100644 --- a/lib/galaxy/tool_shed/util/repository_util.py +++ b/lib/galaxy/tool_shed/util/repository_util.py @@ -22,10 +22,7 @@ from sqlalchemy.orm import joinedload from galaxy import util -from galaxy.model.base import ( - check_database_connection, - transaction, -) +from galaxy.model.base import check_database_connection from galaxy.model.scoped_session import install_model_scoped_session from galaxy.model.tool_shed_install import ToolShedRepository from galaxy.tool_shed.util import basic_util @@ -98,8 +95,7 @@ def _check_or_update_tool_shed_status_for_installed_repository( repository.tool_shed_status = tool_shed_status_dict session = install_model_context session.add(repository) - with transaction(session): - session.commit() + session.commit() updated = True else: @@ -183,8 +179,7 @@ def create_or_update_tool_shed_repository( status=status, ) context.add(tool_shed_repository) - with transaction(context): - context.commit() + context.commit() return tool_shed_repository @@ -769,8 +764,7 @@ def set_repository_attributes(app, repository, status, error_message, deleted, u session = app.install_model.context session.add(repository) - with transaction(session): - session.commit() + session.commit() __all__ = ( diff --git a/lib/galaxy/tool_shed/util/shed_util_common.py b/lib/galaxy/tool_shed/util/shed_util_common.py index 43a1e652b110..72d72a6eab91 100644 --- a/lib/galaxy/tool_shed/util/shed_util_common.py +++ b/lib/galaxy/tool_shed/util/shed_util_common.py @@ -2,7 +2,6 @@ import re from galaxy import util -from galaxy.model.base import transaction from galaxy.tool_shed.util import repository_util from galaxy.util.tool_shed import common_util @@ -46,8 +45,7 @@ def clean_dependency_relationships(trans, metadata_dict, tool_shed_repository, t log.debug(message % (r.name, r.owner, tool_shed_repository.name, tool_shed_repository.owner)) session = trans.install_model.context session.delete(rrda) - with transaction(session): - session.commit() + session.commit() def generate_tool_guid(repository_clone_url, tool): diff --git a/lib/galaxy/tool_shed/util/tool_dependency_util.py b/lib/galaxy/tool_shed/util/tool_dependency_util.py index 58e8643c4c06..0233226021e6 100644 --- a/lib/galaxy/tool_shed/util/tool_dependency_util.py +++ b/lib/galaxy/tool_shed/util/tool_dependency_util.py @@ -5,7 +5,6 @@ from sqlalchemy import and_ from galaxy import util -from galaxy.model.base import transaction log = logging.getLogger(__name__) @@ -216,8 +215,7 @@ def remove_tool_dependency(app, tool_dependency): tool_dependency.status = app.install_model.ToolDependency.installation_status.UNINSTALLED tool_dependency.error_message = None context.add(tool_dependency) - with transaction(context): - context.commit() + context.commit() # Since the received tool_dependency is in an error state, nothing will need to be changed in any # of the in-memory dictionaries in the installed_repository_manager because changing the state from # error to uninstalled requires no in-memory changes.. From f279c2e4cc3052e1e2fdd866125800d124518a3e Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:54:41 -0500 Subject: [PATCH 29/39] Remove transaction helper from galaxy_test --- lib/galaxy_test/driver/uses_shed.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/galaxy_test/driver/uses_shed.py b/lib/galaxy_test/driver/uses_shed.py index f563d516d5a6..ad5490ece2f7 100644 --- a/lib/galaxy_test/driver/uses_shed.py +++ b/lib/galaxy_test/driver/uses_shed.py @@ -7,7 +7,6 @@ from unittest import SkipTest from galaxy.app import UniverseApplication -from galaxy.model.base import transaction from galaxy.util.tool_shed.tool_shed_registry import DEFAULT_TOOL_SHED_URL from galaxy.util.unittest_utils import is_site_up from galaxy_test.base.populators import DEFAULT_TIMEOUT @@ -102,5 +101,4 @@ def reset_shed_tools(self): ] for item in models_to_delete: model.context.query(item).delete() - with transaction(model.context): - model.context.commit() + model.context.commit() From 9cc45fc72a5b7a5032e3551b6684dccd5629cc71 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:57:51 -0500 Subject: [PATCH 30/39] Remove transaction helper from tool_shed.webapp.security --- lib/tool_shed/webapp/security/__init__.py | 25 ++++++++--------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/lib/tool_shed/webapp/security/__init__.py b/lib/tool_shed/webapp/security/__init__.py index 10b7b4ed663a..310435ccb061 100644 --- a/lib/tool_shed/webapp/security/__init__.py +++ b/lib/tool_shed/webapp/security/__init__.py @@ -8,7 +8,6 @@ select, ) -from galaxy.model.base import transaction from galaxy.util import listify from galaxy.util.bunch import Bunch from tool_shed.webapp.model import ( @@ -117,32 +116,28 @@ def associate_group_role(self, group, role): assoc = self.model.GroupRoleAssociation(group, role) self.sa_session.add(assoc) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() return assoc def associate_user_group(self, user, group): assoc = self.model.UserGroupAssociation(user, group) self.sa_session.add(assoc) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() return assoc def associate_user_role(self, user, role): assoc = self.model.UserRoleAssociation(user, role) self.sa_session.add(assoc) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() return assoc def associate_repository_category(self, repository, category): assoc = self.model.RepositoryCategoryAssociation(repository, category) self.sa_session.add(assoc) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() return assoc def create_private_user_role(self, user): @@ -152,8 +147,7 @@ def create_private_user_role(self, user): ) self.sa_session.add(role) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() # Add user to role self.associate_components(role=role, user=user) return role @@ -186,8 +180,7 @@ def set_entity_group_associations(self, groups=None, users=None, roles=None, del for a in group.roles + group.users: self.sa_session.delete(a) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() for role in roles: self.associate_components(group=group, role=role) for user in users: @@ -209,8 +202,7 @@ def set_entity_role_associations( for a in role.users + role.groups: self.sa_session.delete(a) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() for user in users: self.associate_components(user=user, role=role) for group in groups: @@ -228,8 +220,7 @@ def set_entity_user_associations(self, users=None, roles=None, groups=None, dele for a in user.non_private_roles + user.groups: self.sa_session.delete(a) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() self.sa_session.refresh(user) for role in roles: # Make sure we are not creating an additional association with a PRIVATE role From 4da662b9c775354fffd5af498125f2dc0e7d33ea Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 17:59:04 -0500 Subject: [PATCH 31/39] Remove transaction helper from tool_shed.webapp.api2 --- lib/tool_shed/webapp/api2/__init__.py | 4 +--- lib/tool_shed/webapp/api2/repositories.py | 13 ++++--------- lib/tool_shed/webapp/api2/users.py | 7 ++----- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/tool_shed/webapp/api2/__init__.py b/lib/tool_shed/webapp/api2/__init__.py index 52da82a00207..b8f070570631 100644 --- a/lib/tool_shed/webapp/api2/__init__.py +++ b/lib/tool_shed/webapp/api2/__init__.py @@ -29,7 +29,6 @@ from galaxy.exceptions import AdminRequiredException from galaxy.managers.session import GalaxySessionManager from galaxy.managers.users import UserManager -from galaxy.model.base import transaction from galaxy.security.idencoding import IdEncodingHelper from galaxy.util import unicodify from galaxy.web.framework.decorators import require_admin_message @@ -331,8 +330,7 @@ def ensure_valid_session(trans: SessionRequestContext) -> None: # be needed. if prev_galaxy_session: sa_session.add(prev_galaxy_session) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() def set_auth_cookie(trans: SessionRequestContext, session): diff --git a/lib/tool_shed/webapp/api2/repositories.py b/lib/tool_shed/webapp/api2/repositories.py index 24425bbe0239..4fdaf47c7555 100644 --- a/lib/tool_shed/webapp/api2/repositories.py +++ b/lib/tool_shed/webapp/api2/repositories.py @@ -23,7 +23,6 @@ ActionInputError, InsufficientPermissionsException, ) -from galaxy.model.base import transaction from galaxy.webapps.galaxy.api import as_form from tool_shed.context import SessionRequestContext from tool_shed.managers.repositories import ( @@ -386,8 +385,7 @@ def set_malicious( repository_metadata = get_repository_metadata_for_management(trans, encoded_repository_id, changeset_revision) repository_metadata.malicious = True trans.sa_session.add(repository_metadata) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return Response(status_code=status.HTTP_204_NO_CONTENT) @router.delete( @@ -404,8 +402,7 @@ def unset_malicious( repository_metadata = get_repository_metadata_for_management(trans, encoded_repository_id, changeset_revision) repository_metadata.malicious = False trans.sa_session.add(repository_metadata) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return Response(status_code=status.HTTP_204_NO_CONTENT) @router.put( @@ -422,8 +419,7 @@ def set_deprecated( ensure_can_manage(trans, repository) repository.deprecated = True trans.sa_session.add(repository) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return Response(status_code=status.HTTP_204_NO_CONTENT) @router.delete( @@ -440,8 +436,7 @@ def unset_deprecated( ensure_can_manage(trans, repository) repository.deprecated = False trans.sa_session.add(repository) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return Response(status_code=status.HTTP_204_NO_CONTENT) @router.delete( diff --git a/lib/tool_shed/webapp/api2/users.py b/lib/tool_shed/webapp/api2/users.py index f55e51438cbc..54eee1b681cd 100644 --- a/lib/tool_shed/webapp/api2/users.py +++ b/lib/tool_shed/webapp/api2/users.py @@ -24,7 +24,6 @@ ) from galaxy.managers.api_keys import ApiKeyManager from galaxy.managers.users import UserManager -from galaxy.model.base import transaction from galaxy.webapps.base.webapp import create_new_session from tool_shed.context import SessionRequestContext from tool_shed.managers.users import ( @@ -329,8 +328,7 @@ def replace_previous_session(trans, user): new_session = create_new_session(trans, prev_galaxy_session, user) trans.set_galaxy_session(new_session) trans.sa_session.add_all((prev_galaxy_session, new_session)) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() set_auth_cookie(trans, new_session) @@ -342,5 +340,4 @@ def invalidate_user_sessions(session, user_id): .where(GalaxySession.is_valid == true()) ) session.execute(stmt) - with transaction(session): - session.commit() + session.commit() From 7b1a9aa478ae8e39792cac71c431086a732056fe Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 18:00:00 -0500 Subject: [PATCH 32/39] Remove transaction helper from tool_shed.webapp.util --- lib/tool_shed/webapp/util/ratings_util.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/tool_shed/webapp/util/ratings_util.py b/lib/tool_shed/webapp/util/ratings_util.py index b5eff6ff57d9..de338b091359 100644 --- a/lib/tool_shed/webapp/util/ratings_util.py +++ b/lib/tool_shed/webapp/util/ratings_util.py @@ -1,6 +1,5 @@ import logging -from galaxy.model.base import transaction from galaxy.model.item_attrs import UsesItemRatings log = logging.getLogger(__name__) @@ -21,13 +20,11 @@ def rate_item(self, trans, user, item, rating, comment=""): item_rating.rating = rating item_rating.comment = comment trans.sa_session.add(item_rating) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() elif item_rating.rating != rating or item_rating.comment != comment: # User has previously rated item; update rating. item_rating.rating = rating item_rating.comment = comment trans.sa_session.add(item_rating) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return item_rating From 1b316163a33da7fb046475ea04e9d42088458e71 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 18:00:23 -0500 Subject: [PATCH 33/39] Remove transaction helper from tool_shed.webapp.api --- lib/tool_shed/webapp/api/repository_revisions.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/tool_shed/webapp/api/repository_revisions.py b/lib/tool_shed/webapp/api/repository_revisions.py index a49921c0d73d..1e051aa43232 100644 --- a/lib/tool_shed/webapp/api/repository_revisions.py +++ b/lib/tool_shed/webapp/api/repository_revisions.py @@ -10,7 +10,6 @@ util, web, ) -from galaxy.model.base import transaction from galaxy.webapps.base.controller import HTTPBadRequest from tool_shed.util import ( metadata_util, @@ -195,8 +194,7 @@ def update(self, trans, payload, **kwd): repository_metadata.changeset_revision, ) trans.sa_session.add(repository_metadata) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() trans.sa_session.refresh(repository_metadata) repository_metadata_dict = repository_metadata.to_dict( view="element", value_mapper=self.__get_value_mapper(trans) From cee6daaa1197cdf04b1eda709f3152d0ba120435 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 18:02:14 -0500 Subject: [PATCH 34/39] Remove transaction helper from tool_shed.webapp.controllers --- lib/tool_shed/webapp/controllers/admin.py | 25 ++++++----------- lib/tool_shed/webapp/controllers/hg.py | 4 +-- .../webapp/controllers/repository.py | 28 ++++++------------- lib/tool_shed/webapp/controllers/user.py | 22 +++++---------- 4 files changed, 25 insertions(+), 54 deletions(-) diff --git a/lib/tool_shed/webapp/controllers/admin.py b/lib/tool_shed/webapp/controllers/admin.py index f07ce4297192..aca7746d4905 100644 --- a/lib/tool_shed/webapp/controllers/admin.py +++ b/lib/tool_shed/webapp/controllers/admin.py @@ -5,7 +5,6 @@ util, web, ) -from galaxy.model.base import transaction from galaxy.util import inflector from galaxy.web.legacy_framework import grids from galaxy.webapps.base.controller import BaseUIController @@ -151,8 +150,7 @@ def create_category(self, trans, **kwd): # Create the category category = trans.app.model.Category(name=name, description=description) trans.sa_session.add(category) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Update the Tool Shed's repository registry. trans.app.repository_registry.add_category_entry(category) message = f"Category '{escape(category.name)}' has been created" @@ -192,8 +190,7 @@ def delete_repository(self, trans, **kwd): trans.sa_session.add(repository_admin_role) repository.deleted = True trans.sa_session.add(repository) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Update the repository registry. trans.app.repository_registry.remove_entry(repository) deleted_repositories.append(repository.name) @@ -225,8 +222,7 @@ def delete_repository_metadata(self, trans, **kwd): for repository_metadata_id in ids: repository_metadata = metadata_util.get_repository_metadata_by_id(trans.app, repository_metadata_id) trans.sa_session.delete(repository_metadata) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() count = len(ids) message = "Deleted {} repository metadata {}".format(count, inflector.cond_plural(count, "record")) else: @@ -276,8 +272,7 @@ def edit_category(self, trans, **kwd): flush_needed = True if flush_needed: trans.sa_session.add(category) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if original_category_name != new_name: # Update the Tool Shed's repository registry. trans.app.repository_registry.edit_category_entry(original_category_name, new_name) @@ -400,8 +395,7 @@ def undelete_repository(self, trans, **kwd): trans.sa_session.add(repository_admin_role) repository.deleted = False trans.sa_session.add(repository) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if not repository.deprecated: # Update the repository registry. trans.app.repository_registry.add_entry(repository) @@ -436,8 +430,7 @@ def mark_category_deleted(self, trans, **kwd): category = suc.get_category(trans.app, category_id) category.deleted = True trans.sa_session.add(category) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Update the Tool Shed's repository registry. trans.app.repository_registry.remove_category_entry(category) deleted_categories.append(category.name) @@ -466,8 +459,7 @@ def purge_category(self, trans, **kwd): # Delete RepositoryCategoryAssociations for rca in category.repositories: trans.sa_session.delete(rca) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() purged_categories.append(category.name) message = "Purged {} categories: {}".format(len(purged_categories), escape(" ".join(purged_categories))) else: @@ -490,8 +482,7 @@ def undelete_category(self, trans, **kwd): if category.deleted: category.deleted = False trans.sa_session.add(category) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Update the Tool Shed's repository registry. trans.app.repository_registry.add_category_entry(category) undeleted_categories.append(category.name) diff --git a/lib/tool_shed/webapp/controllers/hg.py b/lib/tool_shed/webapp/controllers/hg.py index 035f17e51b1e..7bb8b7bee214 100644 --- a/lib/tool_shed/webapp/controllers/hg.py +++ b/lib/tool_shed/webapp/controllers/hg.py @@ -4,7 +4,6 @@ from galaxy import web from galaxy.exceptions import ObjectNotFound -from galaxy.model.base import transaction from galaxy.webapps.base.controller import BaseUIController from tool_shed.util.repository_util import get_repository_by_name_and_owner @@ -46,6 +45,5 @@ def make_web_app(): times_downloaded += 1 repository.times_downloaded = times_downloaded trans.sa_session.add(repository) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return PortAsStringMiddleware(wsgi_app) diff --git a/lib/tool_shed/webapp/controllers/repository.py b/lib/tool_shed/webapp/controllers/repository.py index 5e2ee39f0e7f..5dffafadc011 100644 --- a/lib/tool_shed/webapp/controllers/repository.py +++ b/lib/tool_shed/webapp/controllers/repository.py @@ -24,7 +24,6 @@ util, web, ) -from galaxy.model.base import transaction from galaxy.model.db.user import get_user_by_username from galaxy.tool_shed.util import dependency_display from galaxy.tools.repositories import ValidationContext @@ -779,8 +778,7 @@ def deprecate(self, trans, **kwd): mark_deprecated = util.string_as_bool(kwd.get("mark_deprecated", False)) repository.deprecated = mark_deprecated trans.sa_session.add(repository) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if mark_deprecated: # Update the repository registry. trans.app.repository_registry.remove_entry(repository) @@ -898,8 +896,7 @@ def download(self, trans, repository_id, changeset_revision, file_type, **kwd): file_type_str = basic_util.get_file_type_str(changeset_revision, file_type) repository.times_downloaded += 1 trans.sa_session.add(repository) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() tool_shed_url = web.url_for("/", qualified=True) pathspec = ["repos", str(repository.user.username), str(repository.name), "archive", file_type_str] download_url = util.build_url(tool_shed_url, pathspec=pathspec) @@ -1592,8 +1589,7 @@ def manage_email_alerts(self, trans, **kwd): if kwd.get("new_repo_alert_button", False): user.new_repo_alert = new_repo_alert_checked trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if new_repo_alert_checked: message = "You will receive email alerts for all new valid tool shed repositories." else: @@ -1664,16 +1660,14 @@ def manage_repository(self, trans, id, **kwd): # Delete all currently existing categories. for rca in repository.categories: trans.sa_session.delete(rca) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if category_ids: # Create category associations for category_id in category_ids: category = trans.sa_session.get(Category, trans.security.decode_id(category_id)) rca = RepositoryCategoryAssociation(repository, category) trans.sa_session.add(rca) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = "The repository information has been updated." elif kwd.get("user_access_button", False): if allow_push not in ["none"]: @@ -1703,8 +1697,7 @@ def manage_repository(self, trans, id, **kwd): flush_needed = True if flush_needed: trans.sa_session.add(repository) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = "The repository information has been updated." if error: status = "error" @@ -2159,8 +2152,7 @@ def set_email_alerts(self, trans, **kwd): flush_needed = True total_alerts_added += 1 if flush_needed: - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = f"Total alerts added: {total_alerts_added}, total alerts removed: {total_alerts_removed}" kwd["message"] = message kwd["status"] = "done" @@ -2176,8 +2168,7 @@ def set_malicious(self, trans, id, ctx_str, **kwd): malicious_checked = CheckboxField.is_checked(malicious) repository_metadata.malicious = malicious_checked trans.sa_session.add(repository_metadata) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if malicious_checked: message = "The repository tip has been defined as malicious." else: @@ -2481,8 +2472,7 @@ def view_repository(self, trans, id, **kwd): flush_needed = True if flush_needed: trans.sa_session.add(repository) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() checked = alerts_checked or (user and user.email in email_alerts) alerts_check_box = CheckboxField("alerts", value=checked) changeset_revision_select_field = grids_util.build_changeset_revision_select_field( diff --git a/lib/tool_shed/webapp/controllers/user.py b/lib/tool_shed/webapp/controllers/user.py index 63016fe8d70e..bf213caa3d90 100644 --- a/lib/tool_shed/webapp/controllers/user.py +++ b/lib/tool_shed/webapp/controllers/user.py @@ -8,7 +8,6 @@ web, ) from galaxy.managers.api_keys import ApiKeyManager -from galaxy.model.base import transaction from galaxy.model.db.user import get_user_by_email from galaxy.security.validate_user_input import ( validate_email, @@ -255,8 +254,7 @@ def reset_password(self, trans, email=None, **kwd): if reset_user: prt = trans.app.model.PasswordResetToken(reset_user) trans.sa_session.add(prt) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() host = trans.request.host.split(":")[0] if host in ["localhost", "127.0.0.1", "0.0.0.0"]: host = socket.getfqdn() @@ -271,8 +269,7 @@ def reset_password(self, trans, email=None, **kwd): try: util.send_mail(frm, email, subject, body, trans.app.config) trans.sa_session.add(reset_user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() trans.log_event(f"User reset password: {email}") except Exception: log.exception("Unable to reset password.") @@ -341,8 +338,7 @@ def edit_username(self, trans, cntrller, **kwd): else: user.username = username trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = "The username has been updated with the changes." return trans.fill_template( "/webapps/tool_shed/user/username.mako", @@ -391,13 +387,11 @@ def edit_info(self, trans, cntrller, **kwd): # Change the email itself user.email = email trans.sa_session.add_all((user, private_role)) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if trans.webapp.name == "galaxy" and trans.app.config.user_activation_on: user.active = False trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() is_activation_sent = self.user_manager.send_activation_email(trans, user.email, user.username) if is_activation_sent: message = "The login information has been updated with the changes.
Verification email has been sent to your new email address. Please verify it by clicking the activation link in the email.
Please check your spam/trash folder in case you cannot find the message." @@ -408,8 +402,7 @@ def edit_info(self, trans, cntrller, **kwd): if user.username != username: user.username = username trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = "The login information has been updated with the changes." elif user and params.get("edit_user_info_button", False): # Edit user information - webapp MUST BE 'galaxy' @@ -440,8 +433,7 @@ def edit_info(self, trans, cntrller, **kwd): flush_needed = True if flush_needed: trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = "The user information has been updated with the changes." if user and trans.webapp.name == "galaxy" and is_admin: kwd["user_id"] = trans.security.encode_id(user.id) From 416bb33c1bf1b2b40587950fc1a52a5ea5b982a9 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 18:03:31 -0500 Subject: [PATCH 35/39] Remove transaction helper from tool_shed.managers --- lib/tool_shed/managers/categories.py | 4 +--- lib/tool_shed/managers/groups.py | 10 +++------- lib/tool_shed/managers/users.py | 4 +--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/tool_shed/managers/categories.py b/lib/tool_shed/managers/categories.py index 13b09297fdbf..e26f7bcdba6d 100644 --- a/lib/tool_shed/managers/categories.py +++ b/lib/tool_shed/managers/categories.py @@ -12,7 +12,6 @@ exceptions, web, ) -from galaxy.model.base import transaction from tool_shed.context import ProvidesUserContext from tool_shed.structured_app import ToolShedApp from tool_shed.webapp.model import Category @@ -39,8 +38,7 @@ def create(self, trans: ProvidesUserContext, category_request: CreateCategoryReq # Create the category category = self.app.model.Category(name=name, description=description) trans.sa_session.add(category) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return category else: raise exceptions.RequestParameterMissingException('Missing required parameter "name".') diff --git a/lib/tool_shed/managers/groups.py b/lib/tool_shed/managers/groups.py index 21f2a6ce0e62..f11b7edf85df 100644 --- a/lib/tool_shed/managers/groups.py +++ b/lib/tool_shed/managers/groups.py @@ -22,7 +22,6 @@ ObjectNotFound, RequestParameterInvalidException, ) -from galaxy.model.base import transaction log = logging.getLogger(__name__) @@ -74,8 +73,7 @@ def create(self, trans, name, description=""): # TODO add description field to the model group = trans.app.model.Group(name=name) trans.sa_session.add(group) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return group def update(self, trans, group, name=None, description=None): @@ -95,8 +93,7 @@ def update(self, trans, group, name=None, description=None): changed = True if changed: trans.sa_session.add(group) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return group def delete(self, trans, group, undelete=False): @@ -110,8 +107,7 @@ def delete(self, trans, group, undelete=False): else: group.deleted = True trans.sa_session.add(group) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() return group def list(self, trans, deleted=False): diff --git a/lib/tool_shed/managers/users.py b/lib/tool_shed/managers/users.py index ef1ca01ff6f5..1c319c6408d3 100644 --- a/lib/tool_shed/managers/users.py +++ b/lib/tool_shed/managers/users.py @@ -3,7 +3,6 @@ from sqlalchemy import select from galaxy.exceptions import RequestParameterInvalidException -from galaxy.model.base import transaction from galaxy.security.validate_user_input import ( validate_email, validate_password, @@ -38,8 +37,7 @@ def create_user(app: ToolShedApp, email: str, username: str, password: str) -> U # else: # user.active = True # Activation is off, every new user is active by default. sa_session.add(user) - with transaction(sa_session): - sa_session.commit() + sa_session.commit() app.security_agent.create_private_user_role(user) return user From 0ca0c3b3e8c3ff8516aaf4dcfcac7e6a739258ce Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 18:04:03 -0500 Subject: [PATCH 36/39] Remove transaction helper from tool_shed.metadata --- .../metadata/repository_metadata_manager.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/tool_shed/metadata/repository_metadata_manager.py b/lib/tool_shed/metadata/repository_metadata_manager.py index 7562459bbbdc..26716442d944 100644 --- a/lib/tool_shed/metadata/repository_metadata_manager.py +++ b/lib/tool_shed/metadata/repository_metadata_manager.py @@ -13,7 +13,6 @@ ) from galaxy import util -from galaxy.model.base import transaction from galaxy.tool_shed.metadata.metadata_generator import ( BaseMetadataGenerator, HandleResultT, @@ -270,8 +269,7 @@ def _add_tool_versions(self, id: int, repository_metadata, changeset_revisions): repository_metadata.tool_versions = tool_versions_dict self.sa_session.add(repository_metadata) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() def build_repository_ids_select_field( self, name="repository_ids", multiple=True, display="checkboxes", my_writable=False @@ -297,8 +295,7 @@ def _clean_repository_metadata(self, changeset_revisions): if changeset_revision not in changeset_revisions: self.sa_session.delete(repository_metadata) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() def compare_changeset_revisions(self, ancestor_changeset_revision, ancestor_metadata_dict): """ @@ -524,8 +521,7 @@ def create_or_update_repository_metadata(self, changeset_revision, metadata_dict repository_metadata.missing_test_components = False self.sa_session.add(repository_metadata) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() return repository_metadata @@ -908,8 +904,7 @@ def _reset_all_tool_versions(self, repo): repository_metadata.tool_versions = tool_versions_dict self.sa_session.add(repository_metadata) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() def reset_metadata_on_selected_repositories(self, **kwd): """ @@ -1021,8 +1016,7 @@ def set_repository_metadata(self, host, content_alert_str="", **kwd): repository_metadata.missing_test_components = False self.sa_session.add(repository_metadata) session = self.sa_session() - with transaction(session): - session.commit() + session.commit() else: # There are no metadata records associated with the repository. repository_metadata = self.create_or_update_repository_metadata( From c06080675dd30ad36ea3514ed33663ecf60ad433 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 18:05:32 -0500 Subject: [PATCH 37/39] Remove transaction helper from tool_shed.util --- lib/tool_shed/util/admin_util.py | 49 +++++++++------------------ lib/tool_shed/util/metadata_util.py | 7 ++-- lib/tool_shed/util/repository_util.py | 7 ++-- 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/lib/tool_shed/util/admin_util.py b/lib/tool_shed/util/admin_util.py index 4e01b03b3369..6730c9195be6 100644 --- a/lib/tool_shed/util/admin_util.py +++ b/lib/tool_shed/util/admin_util.py @@ -16,7 +16,6 @@ Library, LibraryDatasetDatasetAssociation, ) -from galaxy.model.base import transaction from galaxy.security.validate_user_input import validate_password from galaxy.util import inflector from galaxy.util.hash_util import new_secure_hash_v2 @@ -126,8 +125,7 @@ def create_role(self, trans, **kwd): num_in_groups = len(in_groups) + 1 else: num_in_groups = len(in_groups) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = f"Role '{role.name}' has been created with {len(in_users)} associated users and {num_in_groups} associated groups. " if create_group_for_role_checked: message += ( @@ -183,8 +181,7 @@ def rename_role(self, trans, **kwd): role.name = new_name role.description = new_description trans.sa_session.add(role) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = f"Role '{old_name}' has been renamed to '{new_name}'" return trans.response.send_redirect( web.url_for( @@ -223,8 +220,7 @@ def manage_users_and_groups_for_role(self, trans, **kwd): for dhp in history.default_permissions: if role == dhp.role: trans.sa_session.delete(dhp) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() in_groups = [trans.sa_session.get(trans.app.model.Group, x) for x in util.listify(params.in_groups)] trans.app.security_agent.set_entity_role_associations(roles=[role], users=in_users, groups=in_groups) trans.sa_session.refresh(role) @@ -300,8 +296,7 @@ def mark_role_deleted(self, trans, **kwd): role = get_role(trans, role_id) role.deleted = True trans.sa_session.add(role) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message += f" {role.name} " trans.response.send_redirect( web.url_for(controller="admin", action="roles", message=util.sanitize_text(message), status="done") @@ -327,8 +322,7 @@ def undelete_role(self, trans, **kwd): ) role.deleted = False trans.sa_session.add(role) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() undeleted_roles.append(role.name) message = "Undeleted {} roles: {}".format(len(undeleted_roles), " ".join(undeleted_roles)) trans.response.send_redirect( @@ -379,8 +373,7 @@ def purge_role(self, trans, **kwd): # Delete DatasetPermissionss for dp in role.dataset_actions: trans.sa_session.delete(dp) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message += f" {role.name} " trans.response.send_redirect( web.url_for(controller="admin", action="roles", message=util.sanitize_text(message), status="done") @@ -435,8 +428,7 @@ def rename_group(self, trans, **kwd): if group.name != new_name: group.name = new_name trans.sa_session.add(group) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = f"Group '{old_name}' has been renamed to '{new_name}'" return trans.response.send_redirect( web.url_for( @@ -521,8 +513,7 @@ def create_group(self, trans, **kwd): # Create the group group = trans.app.model.Group(name=name) trans.sa_session.add(group) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() # Create the UserRoleAssociations for user in [trans.sa_session.get(trans.app.model.User, x) for x in in_users]: uga = trans.app.model.UserGroupAssociation(user, group) @@ -541,8 +532,7 @@ def create_group(self, trans, **kwd): num_in_roles = len(in_roles) + 1 else: num_in_roles = len(in_roles) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = f"Group '{group.name}' has been created with {len(in_users)} associated users and {num_in_roles} associated roles. " if create_role_for_group_checked: message += ( @@ -584,8 +574,7 @@ def mark_group_deleted(self, trans, **kwd): group = get_group(trans, group_id) group.deleted = True trans.sa_session.add(group) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message += f" {group.name} " trans.response.send_redirect( web.url_for(controller="admin", action="groups", message=util.sanitize_text(message), status="done") @@ -613,8 +602,7 @@ def undelete_group(self, trans, **kwd): ) group.deleted = False trans.sa_session.add(group) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() undeleted_groups.append(group.name) message = "Undeleted {} groups: {}".format(len(undeleted_groups), " ".join(undeleted_groups)) trans.response.send_redirect( @@ -650,8 +638,7 @@ def purge_group(self, trans, **kwd): # Delete GroupRoleAssociations for gra in group.roles: trans.sa_session.delete(gra) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message += f" {group.name} " trans.response.send_redirect( web.url_for(controller="admin", action="groups", message=util.sanitize_text(message), status="done") @@ -686,8 +673,7 @@ def reset_user_password(self, trans, **kwd): else: user.set_password_cleartext(password) trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() if not message and not status: message = "Passwords reset for {} {}.".format( len(user_ids), inflector.cond_plural(len(user_ids), "user") @@ -741,8 +727,7 @@ def mark_user_deleted(self, trans, **kwd): user.username = uname_hash trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message += f" {user.email} " trans.response.send_redirect( web.url_for(controller="admin", action="users", message=util.sanitize_text(message), status="done") @@ -768,8 +753,7 @@ def undelete_user(self, trans, **kwd): ) user.deleted = False trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() undeleted_users.append(user.email) message = "Undeleted {} users: {}".format(len(undeleted_users), " ".join(undeleted_users)) trans.response.send_redirect( @@ -835,8 +819,7 @@ def purge_user(self, trans, **kwd): # Purge the user user.purged = True trans.sa_session.add(user) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message += f"{user.email} " trans.response.send_redirect( web.url_for(controller="admin", action="users", message=util.sanitize_text(message), status="done") diff --git a/lib/tool_shed/util/metadata_util.py b/lib/tool_shed/util/metadata_util.py index 0ca15a8aa919..b7d18f2eaec7 100644 --- a/lib/tool_shed/util/metadata_util.py +++ b/lib/tool_shed/util/metadata_util.py @@ -7,7 +7,6 @@ from sqlalchemy import select -from galaxy.model.base import transaction from galaxy.tool_shed.util.hg_util import ( INITIAL_CHANGELOG_HASH, reversed_lower_upper_bounded_changelog, @@ -150,8 +149,7 @@ def get_metadata_revisions(app, repository, sort_revisions=True, reverse=False, repository_metadata.numeric_revision = rev sa_session.add(repository_metadata) session = sa_session() - with transaction(session): - session.commit() + session.commit() except Exception: rev = -1 else: @@ -269,8 +267,7 @@ def repository_metadata_by_changeset_revision( for repository_metadata in all_metadata_records[1:]: sa_session.delete(repository_metadata) session = sa_session() - with transaction(session): - session.commit() + session.commit() return all_metadata_records[0] elif all_metadata_records: return all_metadata_records[0] diff --git a/lib/tool_shed/util/repository_util.py b/lib/tool_shed/util/repository_util.py index 592c3e9b3b1f..5f198a131fe9 100644 --- a/lib/tool_shed/util/repository_util.py +++ b/lib/tool_shed/util/repository_util.py @@ -23,7 +23,6 @@ util, web, ) -from galaxy.model.base import transaction from galaxy.tool_shed.util.repository_util import ( create_or_update_tool_shed_repository, extract_components_from_tuple, @@ -229,8 +228,7 @@ def create_repository( lhs = f"{app.config.hgweb_repo_prefix}{repository.user.username}/{repository.name}" # Flush to get the id. session = sa_session() - with transaction(session): - session.commit() + session.commit() final_repository_path = repository.ensure_hg_repository_path(app.config.file_path) os.rename(repository_path, final_repository_path) app.hgweb_config_manager.add_entry(lhs, final_repository_path) @@ -498,8 +496,7 @@ def update_validated_repository( if flush_needed: trans.sa_session.add(repository) - with transaction(trans.sa_session): - trans.sa_session.commit() + trans.sa_session.commit() message = "The repository information has been updated." else: message = None From ef1aa62a4b09e144ef23152a3189b3d79d109709 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 18:13:22 -0500 Subject: [PATCH 38/39] Remove transaction helper from test/unit.test_galaxy_transactions --- test/unit/test_galaxy_transactions.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/unit/test_galaxy_transactions.py b/test/unit/test_galaxy_transactions.py index 8093df91c0ce..c3b988505e57 100644 --- a/test/unit/test_galaxy_transactions.py +++ b/test/unit/test_galaxy_transactions.py @@ -4,7 +4,6 @@ from galaxy import model from galaxy.managers import context from galaxy.model import mapping -from galaxy.model.base import transaction as db_transaction from galaxy.util import bunch @@ -67,8 +66,7 @@ def test_expunge_all(transaction): user.password = "bar2" session = transaction.sa_session - with db_transaction(session): - session.commit() + session.commit() assert transaction.sa_session.scalars(select(model.User).limit(1)).first().password == "bar2" @@ -76,8 +74,7 @@ def test_expunge_all(transaction): user.password = "bar3" session = transaction.sa_session - with db_transaction(session): - session.commit() + session.commit() # Password unchange because not attached to session/context. assert transaction.sa_session.scalars(select(model.User).limit(1)).first().password == "bar2" From 1bd861aeb4a76ff52f110a1fadac426cb8fff944 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Jan 2025 18:13:25 -0500 Subject: [PATCH 39/39] Remove transaction helper --- lib/galaxy/model/base.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/lib/galaxy/model/base.py b/lib/galaxy/model/base.py index 2dd49b468ec5..b9e81bdfe017 100644 --- a/lib/galaxy/model/base.py +++ b/lib/galaxy/model/base.py @@ -3,7 +3,6 @@ generalize to generic database connections. """ -import contextlib import logging import os import threading @@ -15,7 +14,6 @@ from typing import ( Dict, Type, - TYPE_CHECKING, Union, ) @@ -23,15 +21,11 @@ from sqlalchemy.orm import ( object_session, scoped_session, - Session, sessionmaker, ) from galaxy.util.bunch import Bunch -if TYPE_CHECKING: - from galaxy.model.store import SessionlessContext - log = logging.getLogger(__name__) # Create a ContextVar with mutable state, this allows sync tasks in the context @@ -41,21 +35,6 @@ REQUEST_ID: ContextVar[Union[Dict[str, str], None]] = ContextVar("request_id", default=None) -@contextlib.contextmanager -def transaction(session: Union[scoped_session, Session, "SessionlessContext"]): - """Start a new transaction only if one is not present.""" - # TODO The `session.begin` code has been removed. Once we can verify this does not break SQLAlchemy transactions, remove this helper + all references (561) - # temporary hack; need to fix access to scoped_session callable, not proxy - if isinstance(session, scoped_session): - session = session() - # hack: this could be model.store.SessionlessContext; then we don't need to do anything - elif not isinstance(session, Session): - yield - return # exit: can't use as a Session - - yield - - def check_database_connection(session): """ In the event of a database disconnect, if there exists an active database