Skip to content

Commit

Permalink
Merge pull request #1437 from pyiron/force_bool_restart
Browse files Browse the repository at this point in the history
Force user to use `bool` for `delete_existing_job`
  • Loading branch information
samwaseda committed May 23, 2024
2 parents c8e7c90 + fea0fb4 commit f9513e1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pyiron_base/jobs/job/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,12 @@ def run(
run_mode (str): ['modal', 'non_modal', 'queue', 'manual'] overwrites self.server.run_mode
run_again (bool): Same as delete_existing_job (deprecated)
"""
if not isinstance(delete_existing_job, bool):
raise ValueError(
f"We got delete_existing_job = {delete_existing_job}. If you"
" meant to delete the job, set delete_existing_job"
" = True"
)
with catch_signals(self.signal_intercept):
if run_again:
delete_existing_job = True
Expand Down
5 changes: 5 additions & 0 deletions pyiron_base/jobs/job/jobtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def __new__(
Returns:
GenericJob: object of type class_name
"""
if not isinstance(delete_existing_job, bool):
raise ValueError(
f"We got delete_existing_job = {delete_existing_job}. If you"
" meant to delete the job, set delete_existing_job = True"
)
job_name = _get_safe_job_name(job_name)
cls.job_class_dict = job_class_dict or cls._job_class_dict
if isinstance(class_name, str):
Expand Down
12 changes: 12 additions & 0 deletions tests/job/test_genericJob.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,18 @@ def test_run_if_suspended(self):
def test_run_if_finished(self):
pass

def test_delete_existing_job_to_be_bool(self):
with self.assertRaises(
ValueError, msg="`delete_existing_job = like_this` must not pass"
):
job = self.project.create_job(ToyJob, "set_non_bool", "like_this")
with self.assertRaises(
ValueError, msg="`delete_existing_job = 10` must not pass"
):
job = self.project.create_job(ToyJob, "set_non_bool_10")
job.input.data_in = 10
job.run(job.input.data_in)

def test_run_with_delete_existing_job_for_aborted_jobs(self):
job = self.project.create_job(ToyJob, "rerun_aborted")
with self.subTest("Drop to aborted if validate_ready_to_run fails"):
Expand Down

0 comments on commit f9513e1

Please sign in to comment.