Skip to content

Commit 9953e07

Browse files
authored
Merge pull request #19388 from jdavcs/dev_sa20_cleanup
SQLAlchemy 2.0 follow-up
2 parents d023b32 + 0acf625 commit 9953e07

File tree

2 files changed

+31
-72
lines changed

2 files changed

+31
-72
lines changed

lib/galaxy/model/__init__.py

+29-67
Original file line numberDiff line numberDiff line change
@@ -803,22 +803,22 @@ class User(Base, Dictifiable, RepresentById):
803803
activation_token: Mapped[Optional[str]] = mapped_column(TrimmedString(64), index=True)
804804

805805
addresses: Mapped[List["UserAddress"]] = relationship(
806-
back_populates="user", order_by=lambda: desc(UserAddress.update_time), cascade_backrefs=False
806+
back_populates="user", order_by=lambda: desc(UserAddress.update_time)
807807
)
808808
custos_auth: Mapped[List["CustosAuthnzToken"]] = relationship(back_populates="user")
809809
chat_exchanges: Mapped[List["ChatExchange"]] = relationship(back_populates="user")
810810
default_permissions: Mapped[List["DefaultUserPermissions"]] = relationship(back_populates="user")
811811
groups: Mapped[List["UserGroupAssociation"]] = relationship(back_populates="user")
812812
histories: Mapped[List["History"]] = relationship(
813-
back_populates="user", order_by=lambda: desc(History.update_time), cascade_backrefs=False # type: ignore[has-type]
813+
back_populates="user", order_by=lambda: desc(History.update_time) # type: ignore[has-type]
814814
)
815815
active_histories: Mapped[List["History"]] = relationship(
816816
primaryjoin=(lambda: (History.user_id == User.id) & (not_(History.deleted)) & (not_(History.archived))),
817817
viewonly=True,
818818
order_by=lambda: desc(History.update_time), # type: ignore[has-type]
819819
)
820820
galaxy_sessions: Mapped[List["GalaxySession"]] = relationship(
821-
back_populates="user", order_by=lambda: desc(GalaxySession.update_time), cascade_backrefs=False
821+
back_populates="user", order_by=lambda: desc(GalaxySession.update_time)
822822
)
823823
object_stores: Mapped[List["UserObjectStore"]] = relationship(back_populates="user")
824824
file_sources: Mapped[List["UserFileSource"]] = relationship(back_populates="user")
@@ -853,11 +853,8 @@ class User(Base, Dictifiable, RepresentById):
853853
stored_workflows: Mapped[List["StoredWorkflow"]] = relationship(
854854
back_populates="user",
855855
primaryjoin=(lambda: User.id == StoredWorkflow.user_id),
856-
cascade_backrefs=False,
857-
)
858-
all_notifications: Mapped[List["UserNotificationAssociation"]] = relationship(
859-
back_populates="user", cascade_backrefs=False
860856
)
857+
all_notifications: Mapped[List["UserNotificationAssociation"]] = relationship(back_populates="user")
861858

862859
preferences: AssociationProxy[Any]
863860

@@ -1507,9 +1504,7 @@ class Job(Base, JobLike, UsesCreateAndUpdateTime, Dictifiable, Serializable):
15071504
output_dataset_collections: Mapped[List["JobToImplicitOutputDatasetCollectionAssociation"]] = relationship(
15081505
back_populates="job"
15091506
)
1510-
post_job_actions: Mapped[List["PostJobActionAssociation"]] = relationship(
1511-
back_populates="job", cascade_backrefs=False
1512-
)
1507+
post_job_actions: Mapped[List["PostJobActionAssociation"]] = relationship(back_populates="job")
15131508
input_library_datasets: Mapped[List["JobToInputLibraryDatasetAssociation"]] = relationship(back_populates="job")
15141509
output_library_datasets: Mapped[List["JobToOutputLibraryDatasetAssociation"]] = relationship(back_populates="job")
15151510
external_output_metadata: Mapped[List["JobExternalOutputMetadata"]] = relationship(back_populates="job")
@@ -1522,17 +1517,17 @@ class Job(Base, JobLike, UsesCreateAndUpdateTime, Dictifiable, Serializable):
15221517
back_populates="job", uselist=True
15231518
)
15241519
implicit_collection_jobs_association: Mapped[List["ImplicitCollectionJobsJobAssociation"]] = relationship(
1525-
back_populates="job", uselist=False, cascade_backrefs=False
1520+
back_populates="job", uselist=False
15261521
)
15271522
container: Mapped[Optional["JobContainerAssociation"]] = relationship(back_populates="job", uselist=False)
15281523
data_manager_association: Mapped[Optional["DataManagerJobAssociation"]] = relationship(
1529-
back_populates="job", uselist=False, cascade_backrefs=False
1524+
back_populates="job", uselist=False
15301525
)
15311526
history_dataset_collection_associations: Mapped[List["HistoryDatasetCollectionAssociation"]] = relationship(
15321527
back_populates="job"
15331528
)
15341529
workflow_invocation_step: Mapped[Optional["WorkflowInvocationStep"]] = relationship(
1535-
back_populates="job", uselist=False, cascade_backrefs=False
1530+
back_populates="job", uselist=False
15361531
)
15371532

15381533
any_output_dataset_collection_instances_deleted = None
@@ -2607,9 +2602,7 @@ class ImplicitCollectionJobs(Base, Serializable):
26072602

26082603
id: Mapped[int] = mapped_column(primary_key=True)
26092604
populated_state: Mapped[str] = mapped_column(TrimmedString(64), default="new")
2610-
jobs: Mapped[List["ImplicitCollectionJobsJobAssociation"]] = relationship(
2611-
back_populates="implicit_collection_jobs", cascade_backrefs=False
2612-
)
2605+
jobs: Mapped[List["ImplicitCollectionJobsJobAssociation"]] = relationship(back_populates="implicit_collection_jobs")
26132606

26142607
class populated_states(str, Enum):
26152608
NEW = "new" # New implicit jobs object, unpopulated job associations
@@ -3029,7 +3022,7 @@ class Group(Base, Dictifiable, RepresentById):
30293022
name: Mapped[Optional[str]] = mapped_column(String(255), index=True, unique=True)
30303023
deleted: Mapped[Optional[bool]] = mapped_column(index=True, default=False)
30313024
quotas: Mapped[List["GroupQuotaAssociation"]] = relationship(back_populates="group")
3032-
roles: Mapped[List["GroupRoleAssociation"]] = relationship(back_populates="group", cascade_backrefs=False)
3025+
roles: Mapped[List["GroupRoleAssociation"]] = relationship(back_populates="group")
30333026
users: Mapped[List["UserGroupAssociation"]] = relationship("UserGroupAssociation", back_populates="group")
30343027

30353028
dict_collection_visible_keys = ["id", "name"]
@@ -3190,7 +3183,7 @@ class History(Base, HasTags, Dictifiable, UsesAnnotations, HasName, Serializable
31903183
archive_export_id: Mapped[Optional[int]] = mapped_column(ForeignKey("store_export_association.id"), default=None)
31913184

31923185
datasets: Mapped[List["HistoryDatasetAssociation"]] = relationship(
3193-
back_populates="history", cascade_backrefs=False, order_by=lambda: asc(HistoryDatasetAssociation.hid) # type: ignore[has-type]
3186+
back_populates="history", order_by=lambda: asc(HistoryDatasetAssociation.hid) # type: ignore[has-type]
31943187
)
31953188
exports: Mapped[List["JobExportHistoryArchive"]] = relationship(
31963189
back_populates="history",
@@ -3255,11 +3248,9 @@ class History(Base, HasTags, Dictifiable, UsesAnnotations, HasName, Serializable
32553248
default_permissions: Mapped[List["DefaultHistoryPermissions"]] = relationship(back_populates="history")
32563249
users_shared_with: Mapped[List["HistoryUserShareAssociation"]] = relationship(back_populates="history")
32573250
galaxy_sessions = relationship("GalaxySessionToHistoryAssociation", back_populates="history")
3258-
workflow_invocations: Mapped[List["WorkflowInvocation"]] = relationship(
3259-
back_populates="history", cascade_backrefs=False
3260-
)
3251+
workflow_invocations: Mapped[List["WorkflowInvocation"]] = relationship(back_populates="history")
32613252
user: Mapped[Optional["User"]] = relationship(back_populates="histories")
3262-
jobs: Mapped[List["Job"]] = relationship(back_populates="history", cascade_backrefs=False)
3253+
jobs: Mapped[List["Job"]] = relationship(back_populates="history")
32633254
tool_requests: Mapped[List["ToolRequest"]] = relationship(back_populates="history")
32643255

32653256
update_time = column_property(
@@ -3916,9 +3907,7 @@ class Quota(Base, Dictifiable, RepresentById):
39163907
operation: Mapped[Optional[str]] = mapped_column(String(8))
39173908
deleted: Mapped[Optional[bool]] = mapped_column(index=True, default=False)
39183909
quota_source_label: Mapped[Optional[str]] = mapped_column(String(32), default=None)
3919-
default: Mapped[List["DefaultQuotaAssociation"]] = relationship(
3920-
"DefaultQuotaAssociation", back_populates="quota", cascade_backrefs=False
3921-
)
3910+
default: Mapped[List["DefaultQuotaAssociation"]] = relationship("DefaultQuotaAssociation", back_populates="quota")
39223911
groups: Mapped[List["GroupQuotaAssociation"]] = relationship(back_populates="quota")
39233912
users: Mapped[List["UserQuotaAssociation"]] = relationship(back_populates="quota")
39243913

@@ -4200,15 +4189,12 @@ class Dataset(Base, StorableObject, Serializable):
42004189
),
42014190
viewonly=True,
42024191
)
4203-
hashes: Mapped[List["DatasetHash"]] = relationship(back_populates="dataset", cascade_backrefs=False)
4192+
hashes: Mapped[List["DatasetHash"]] = relationship(back_populates="dataset")
42044193
sources: Mapped[List["DatasetSource"]] = relationship(back_populates="dataset")
4205-
history_associations: Mapped[List["HistoryDatasetAssociation"]] = relationship(
4206-
back_populates="dataset", cascade_backrefs=False
4207-
)
4194+
history_associations: Mapped[List["HistoryDatasetAssociation"]] = relationship(back_populates="dataset")
42084195
library_associations: Mapped[List["LibraryDatasetDatasetAssociation"]] = relationship(
42094196
primaryjoin=(lambda: LibraryDatasetDatasetAssociation.table.c.dataset_id == Dataset.id),
42104197
back_populates="dataset",
4211-
cascade_backrefs=False,
42124198
)
42134199

42144200
# failed_metadata is only valid as DatasetInstance state currently
@@ -5779,7 +5765,7 @@ class Library(Base, Dictifiable, HasName, Serializable):
57795765
description: Mapped[Optional[str]] = mapped_column(TEXT)
57805766
synopsis: Mapped[Optional[str]] = mapped_column(TEXT)
57815767
root_folder = relationship("LibraryFolder", back_populates="library_root")
5782-
actions: Mapped[List["LibraryPermissions"]] = relationship(back_populates="library", cascade_backrefs=False)
5768+
actions: Mapped[List["LibraryPermissions"]] = relationship(back_populates="library")
57835769

57845770
permitted_actions = get_permitted_actions(filter="LIBRARY")
57855771
dict_collection_visible_keys = ["id", "name"]
@@ -5894,7 +5880,7 @@ class LibraryFolder(Base, Dictifiable, HasName, Serializable):
58945880
)
58955881

58965882
library_root = relationship("Library", back_populates="root_folder")
5897-
actions: Mapped[List["LibraryFolderPermissions"]] = relationship(back_populates="folder", cascade_backrefs=False)
5883+
actions: Mapped[List["LibraryFolderPermissions"]] = relationship(back_populates="folder")
58985884

58995885
dict_element_visible_keys = [
59005886
"id",
@@ -6016,9 +6002,7 @@ class LibraryDataset(Base, Serializable):
60166002
viewonly=True,
60176003
uselist=True,
60186004
)
6019-
actions: Mapped[List["LibraryDatasetPermissions"]] = relationship(
6020-
back_populates="library_dataset", cascade_backrefs=False
6021-
)
6005+
actions: Mapped[List["LibraryDatasetPermissions"]] = relationship(back_populates="library_dataset")
60226006

60236007
# This class acts as a proxy to the currently selected LDDA
60246008
upload_options = [
@@ -7651,7 +7635,7 @@ class GalaxySession(Base, RepresentById):
76517635
last_action: Mapped[Optional[datetime]]
76527636
current_history: Mapped[Optional["History"]] = relationship()
76537637
histories: Mapped[List["GalaxySessionToHistoryAssociation"]] = relationship(
7654-
back_populates="galaxy_session", cascade_backrefs=False
7638+
back_populates="galaxy_session",
76557639
)
76567640
user: Mapped[Optional["User"]] = relationship(back_populates="galaxy_sessions")
76577641

@@ -7729,7 +7713,6 @@ class StoredWorkflow(Base, HasTags, Dictifiable, RepresentById, UsesCreateAndUpd
77297713
cascade="all, delete-orphan",
77307714
primaryjoin=(lambda: StoredWorkflow.id == Workflow.stored_workflow_id),
77317715
order_by=lambda: -Workflow.id,
7732-
cascade_backrefs=False,
77337716
)
77347717
latest_workflow: Mapped["Workflow"] = relationship(
77357718
"Workflow",
@@ -7922,7 +7905,6 @@ class Workflow(Base, Dictifiable, RepresentById):
79227905
"WorkflowStep",
79237906
primaryjoin=(lambda: Workflow.id == WorkflowStep.subworkflow_id),
79247907
back_populates="subworkflow",
7925-
cascade_backrefs=False,
79267908
)
79277909
stored_workflow = relationship(
79287910
"StoredWorkflow",
@@ -8129,18 +8111,15 @@ class WorkflowStep(Base, RepresentById, UsesCreateAndUpdateTime):
81298111
order_by=lambda: WorkflowStepAnnotationAssociation.id,
81308112
back_populates="workflow_step",
81318113
)
8132-
post_job_actions = relationship("PostJobAction", back_populates="workflow_step", cascade_backrefs=False)
8114+
post_job_actions = relationship("PostJobAction", back_populates="workflow_step")
81338115
inputs = relationship("WorkflowStepInput", back_populates="workflow_step")
8134-
workflow_outputs: Mapped[List["WorkflowOutput"]] = relationship(
8135-
back_populates="workflow_step", cascade_backrefs=False
8136-
)
8116+
workflow_outputs: Mapped[List["WorkflowOutput"]] = relationship(back_populates="workflow_step")
81378117
output_connections: Mapped[List["WorkflowStepConnection"]] = relationship(
81388118
primaryjoin=(lambda: WorkflowStepConnection.output_step_id == WorkflowStep.id)
81398119
)
81408120
workflow: Mapped["Workflow"] = relationship(
81418121
primaryjoin=(lambda: Workflow.id == WorkflowStep.workflow_id),
81428122
back_populates="steps",
8143-
cascade_backrefs=False,
81448123
)
81458124

81468125
STEP_TYPE_TO_INPUT_TYPE = {
@@ -8445,7 +8424,6 @@ class WorkflowStepInput(Base, RepresentById):
84458424
connections: Mapped[List["WorkflowStepConnection"]] = relationship(
84468425
back_populates="input_step_input",
84478426
primaryjoin=(lambda: WorkflowStepConnection.input_step_input_id == WorkflowStepInput.id),
8448-
cascade_backrefs=False,
84498427
)
84508428

84518429
def __init__(self, workflow_step):
@@ -8695,20 +8673,13 @@ class WorkflowInvocation(Base, UsesCreateAndUpdateTime, Dictifiable, Serializabl
86958673
history_id: Mapped[Optional[int]] = mapped_column(ForeignKey("history.id"), index=True)
86968674

86978675
history = relationship("History", back_populates="workflow_invocations")
8698-
input_parameters = relationship(
8699-
"WorkflowRequestInputParameter", back_populates="workflow_invocation", cascade_backrefs=False
8700-
)
8701-
step_states = relationship("WorkflowRequestStepState", back_populates="workflow_invocation", cascade_backrefs=False)
8702-
input_step_parameters = relationship(
8703-
"WorkflowRequestInputStepParameter", back_populates="workflow_invocation", cascade_backrefs=False
8704-
)
8705-
input_datasets = relationship(
8706-
"WorkflowRequestToInputDatasetAssociation", back_populates="workflow_invocation", cascade_backrefs=False
8707-
)
8676+
input_parameters = relationship("WorkflowRequestInputParameter", back_populates="workflow_invocation")
8677+
step_states = relationship("WorkflowRequestStepState", back_populates="workflow_invocation")
8678+
input_step_parameters = relationship("WorkflowRequestInputStepParameter", back_populates="workflow_invocation")
8679+
input_datasets = relationship("WorkflowRequestToInputDatasetAssociation", back_populates="workflow_invocation")
87088680
input_dataset_collections = relationship(
87098681
"WorkflowRequestToInputDatasetCollectionAssociation",
87108682
back_populates="workflow_invocation",
8711-
cascade_backrefs=False,
87128683
)
87138684
subworkflow_invocations = relationship(
87148685
"WorkflowInvocationToSubworkflowInvocationAssociation",
@@ -8722,20 +8693,14 @@ class WorkflowInvocation(Base, UsesCreateAndUpdateTime, Dictifiable, Serializabl
87228693
"WorkflowInvocationStep",
87238694
back_populates="workflow_invocation",
87248695
order_by=lambda: WorkflowInvocationStep.order_index,
8725-
cascade_backrefs=False,
87268696
)
87278697
workflow = relationship("Workflow")
87288698
output_dataset_collections = relationship(
87298699
"WorkflowInvocationOutputDatasetCollectionAssociation",
87308700
back_populates="workflow_invocation",
8731-
cascade_backrefs=False,
8732-
)
8733-
output_datasets = relationship(
8734-
"WorkflowInvocationOutputDatasetAssociation", back_populates="workflow_invocation", cascade_backrefs=False
8735-
)
8736-
output_values = relationship(
8737-
"WorkflowInvocationOutputValue", back_populates="workflow_invocation", cascade_backrefs=False
87388701
)
8702+
output_datasets = relationship("WorkflowInvocationOutputDatasetAssociation", back_populates="workflow_invocation")
8703+
output_values = relationship("WorkflowInvocationOutputValue", back_populates="workflow_invocation")
87398704
messages = relationship("WorkflowInvocationMessage", back_populates="workflow_invocation")
87408705

87418706
dict_collection_visible_keys = [
@@ -9422,12 +9387,10 @@ class WorkflowInvocationStep(Base, Dictifiable, Serializable):
94229387
output_dataset_collections = relationship(
94239388
"WorkflowInvocationStepOutputDatasetCollectionAssociation",
94249389
back_populates="workflow_invocation_step",
9425-
cascade_backrefs=False,
94269390
)
94279391
output_datasets = relationship(
94289392
"WorkflowInvocationStepOutputDatasetAssociation",
94299393
back_populates="workflow_invocation_step",
9430-
cascade_backrefs=False,
94319394
)
94329395
workflow_invocation: Mapped["WorkflowInvocation"] = relationship(back_populates="steps")
94339396
output_value = relationship(
@@ -10617,7 +10580,6 @@ class Visualization(Base, HasTags, Dictifiable, RepresentById, UsesCreateAndUpda
1061710580
back_populates="visualization",
1061810581
cascade="all, delete-orphan",
1061910582
primaryjoin=(lambda: Visualization.id == VisualizationRevision.visualization_id),
10620-
cascade_backrefs=False,
1062110583
)
1062210584
latest_revision: Mapped[Optional["VisualizationRevision"]] = relationship(
1062310585
post_update=True,
@@ -11776,7 +11738,7 @@ def __repr__(self):
1177611738
_metadata=deferred(HistoryDatasetAssociation.table.c._metadata),
1177711739
dependent_jobs=relationship(JobToInputDatasetAssociation, back_populates="dataset"),
1177811740
creating_job_associations=relationship(JobToOutputDatasetAssociation, back_populates="dataset"),
11779-
history=relationship(History, back_populates="datasets", cascade_backrefs=False),
11741+
history=relationship(History, back_populates="datasets"),
1178011742
implicitly_converted_datasets=relationship(
1178111743
ImplicitlyConvertedDatasetAssociation,
1178211744
primaryjoin=(lambda: ImplicitlyConvertedDatasetAssociation.hda_parent_id == HistoryDatasetAssociation.id),

lib/galaxy/model/base.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
@contextlib.contextmanager
4545
def transaction(session: Union[scoped_session, Session, "SessionlessContext"]):
4646
"""Start a new transaction only if one is not present."""
47+
# TODO The `session.begin` code has been removed. Once we can verify this does not break SQLAlchemy transactions, remove this helper + all references (561)
4748
# temporary hack; need to fix access to scoped_session callable, not proxy
4849
if isinstance(session, scoped_session):
4950
session = session()
@@ -52,11 +53,7 @@ def transaction(session: Union[scoped_session, Session, "SessionlessContext"]):
5253
yield
5354
return # exit: can't use as a Session
5455

55-
if not session.in_transaction(): # type:ignore[union-attr]
56-
with session.begin(): # type:ignore[union-attr]
57-
yield
58-
else:
59-
yield
56+
yield
6057

6158

6259
def check_database_connection(session):

0 commit comments

Comments
 (0)