diff --git a/lib/galaxy/job_execution/setup.py b/lib/galaxy/job_execution/setup.py index addb3bb4b3f..b7c1de94110 100644 --- a/lib/galaxy/job_execution/setup.py +++ b/lib/galaxy/job_execution/setup.py @@ -393,20 +393,13 @@ class JobWorkingDirectory: def create(self) -> str: """Create the working directory and return its path. - Raises ``FileExistsError`` if the per-job directory already exists - (job id collision or leftover from a crashed run). + Idempotent: if the per-job directory already exists (e.g. wrapper + reconstruction for a resubmitted job), it is returned without error. """ if custom_path := self._custom_path: validate_working_directory_path(custom_path) path = self._per_job_path(custom_path) - try: - os.makedirs(path, exist_ok=False) - except FileExistsError as exc: - raise FileExistsError( - f"Job working directory already exists for job {self._job.id} " - f"at {path!r}; this indicates a job id collision or a leftover " - f"directory from a previous run." - ) from exc + os.makedirs(path, exist_ok=True) return path self._object_store.create( self._job, diff --git a/test/unit/job_execution/test_job_working_directory.py b/test/unit/job_execution/test_job_working_directory.py index 28d1f21b3bc..b1f24818441 100644 --- a/test/unit/job_execution/test_job_working_directory.py +++ b/test/unit/job_execution/test_job_working_directory.py @@ -68,15 +68,17 @@ class TestJobWorkingDirectoryCustomPath: # The base must exist too (as parent of the per-job dir). assert os.path.isdir(base) - def test_create_raises_on_preexisting_per_job_dir(self, tmp_path, object_store): + def test_create_is_idempotent_on_preexisting_per_job_dir(self, tmp_path, object_store): + """create() returns the same path without error if the directory already exists.""" base = str(tmp_path / "jobs") job = _make_job(100) job.working_directory = base jwd = JobWorkingDirectory(job, object_store) - jwd.create() - with pytest.raises(FileExistsError, match="already exists for job 100"): - jwd.create() + path1 = jwd.create() + path2 = jwd.create() + assert path1 == path2 + assert os.path.isdir(path1) def test_exists_reflects_per_job_dir(self, tmp_path, object_store): base = str(tmp_path / "jobs")