Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove transaction helper #19407

Open
wants to merge 39 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f0de72b
Remove transaction helper from test.unit.job_execution
jdavcs Jan 14, 2025
f39702b
Remove transaction helper from test.unit.workflows
jdavcs Jan 14, 2025
6f47682
Remove transaction helper from test.unit.data
jdavcs Jan 14, 2025
a26cd0f
Remove transaction helper from test.unit.app.jobs
jdavcs Jan 14, 2025
1ce27e3
Remove transaction helper from test.unit.app.managers
jdavcs Jan 14, 2025
dee8804
Remove transaction helper from test.unit.app.tools
jdavcs Jan 14, 2025
62155b9
Remove transaction helper from test.integration
jdavcs Jan 14, 2025
896d084
Remove transaction helper from scripts
jdavcs Jan 14, 2025
7886de0
Fix typo
jdavcs Jan 14, 2025
79f44a2
Remove transaction helper from galaxy.security
jdavcs Jan 14, 2025
6575666
Remove transaction helper from galaxy.model
jdavcs Jan 14, 2025
dd221af
Remove transaction helper from galaxy.tools
jdavcs Jan 14, 2025
cf4f7f9
Remove transaction helper from galaxy.job_execution
jdavcs Jan 14, 2025
87bb447
Remove transaction helper from galaxy.managers
jdavcs Jan 14, 2025
74e4c97
Remove transaction helper from galaxy.quota
jdavcs Jan 14, 2025
bc13d78
Remove transaction helper from galaxy.celery
jdavcs Jan 14, 2025
6125c2e
Remove transaction helper from galaxy.app_unittest_utils
jdavcs Jan 14, 2025
8af74a8
Remove transaction helper from galaxy.work
jdavcs Jan 14, 2025
e65045e
Remove transaction helper from galaxy.authnz
jdavcs Jan 14, 2025
7275332
Remove transaction helper from galaxy.workflow
jdavcs Jan 14, 2025
85b9697
Remove transaction helper from galaxy.actions
jdavcs Jan 14, 2025
b8fe28d
Remove transaction helper from galaxy.jobs
jdavcs Jan 14, 2025
70aa1d6
Remove transaction helper from galaxy.web_stack
jdavcs Jan 14, 2025
2f60482
Remove transaction helper from galaxy.webapps.base
jdavcs Jan 14, 2025
226e00d
Remove transaction helper from galaxy.webapps.galaxy.api
jdavcs Jan 14, 2025
c995c36
Remove transaction helper from galaxy.webapps.galaxy.services
jdavcs Jan 14, 2025
17ebf87
Remove transaction helper from galaxy.webapps.galaxy.controllers
jdavcs Jan 14, 2025
5b79724
Remove transaction helper from galaxy.tool_shed
jdavcs Jan 14, 2025
f279c2e
Remove transaction helper from galaxy_test
jdavcs Jan 14, 2025
9cc45fc
Remove transaction helper from tool_shed.webapp.security
jdavcs Jan 14, 2025
4da662b
Remove transaction helper from tool_shed.webapp.api2
jdavcs Jan 14, 2025
7b1a9aa
Remove transaction helper from tool_shed.webapp.util
jdavcs Jan 14, 2025
1b31616
Remove transaction helper from tool_shed.webapp.api
jdavcs Jan 14, 2025
cee6daa
Remove transaction helper from tool_shed.webapp.controllers
jdavcs Jan 14, 2025
416bb33
Remove transaction helper from tool_shed.managers
jdavcs Jan 14, 2025
0ca0c3b
Remove transaction helper from tool_shed.metadata
jdavcs Jan 14, 2025
c060806
Remove transaction helper from tool_shed.util
jdavcs Jan 14, 2025
ef1aa62
Remove transaction helper from test/unit.test_galaxy_transactions
jdavcs Jan 14, 2025
1bd861a
Remove transaction helper
jdavcs Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/galaxy/actions/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions lib/galaxy/app_unittest_utils/galaxy_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 4 additions & 9 deletions lib/galaxy/app_unittest_utils/toolbox_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -123,25 +121,22 @@ 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
version_association.tool_id = version2.id

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:
Expand Down
10 changes: 3 additions & 7 deletions lib/galaxy/authnz/custos_authnz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/galaxy/authnz/psa_authnz.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
PSAPartial,
UserAuthnzToken,
)
from galaxy.model.base import transaction
from galaxy.util import (
DEFAULT_SOCKET_TIMEOUT,
requests,
Expand Down Expand Up @@ -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()
67 changes: 31 additions & 36 deletions lib/galaxy/celery/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
10 changes: 3 additions & 7 deletions lib/galaxy/celery/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand All @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 4 additions & 9 deletions lib/galaxy/job_execution/output_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Loading
Loading