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

Force user to use bool for delete_existing_job #1437

Merged
merged 7 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading