diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index fd75e87931eb..32550f11fd93 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -2999,7 +2999,7 @@ class History(Base, HasTags, Dictifiable, UsesAnnotations, HasName, Serializable galaxy_sessions = relationship("GalaxySessionToHistoryAssociation", back_populates="history") workflow_invocations = relationship("WorkflowInvocation", back_populates="history", cascade_backrefs=False) user = relationship("User", back_populates="histories") - jobs = relationship("Job", back_populates="history") + jobs = relationship("Job", back_populates="history", cascade_backrefs=False) update_time = column_property( select(func.max(HistoryAudit.update_time)).where(HistoryAudit.history_id == id).scalar_subquery(), diff --git a/test/integration/test_job_files.py b/test/integration/test_job_files.py index f45cd6a722e1..f9f6cfaae540 100644 --- a/test/integration/test_job_files.py +++ b/test/integration/test_job_files.py @@ -20,6 +20,7 @@ import requests from sqlalchemy import select +from sqlalchemy.orm import object_session from galaxy import model from galaxy.model.base import transaction @@ -138,6 +139,8 @@ def create_static_job_with_state(self, state): sa_session.commit() job = model.Job() job.history = history + # Safeguard: job was implicitly merged into this Session prior to SQLAlchemy 2.0. + object_session(history).add(job) job.user = user job.handler = "unknown-handler" job.state = state