diff --git a/aiida/schedulers/plugins/sge.py b/aiida/schedulers/plugins/sge.py index 85e55eb89c..c07f92e503 100644 --- a/aiida/schedulers/plugins/sge.py +++ b/aiida/schedulers/plugins/sge.py @@ -206,7 +206,7 @@ def _get_submit_script_header(self, job_tmpl): if not job_title or (job_title[0] not in string.ascii_letters): job_title = f'j{job_title}' - lines.append(f'#$ -N {job_tmpl.job_name}') + lines.append(f'#$ -N {job_title}') if job_tmpl.import_sys_environment: lines.append('#$ -V') diff --git a/tests/schedulers/test_sge.py b/tests/schedulers/test_sge.py index 2c5fa680b9..cfa6cb543e 100644 --- a/tests/schedulers/test_sge.py +++ b/tests/schedulers/test_sge.py @@ -356,3 +356,16 @@ def _parse_time_string(string, fmt='%Y-%m-%dT%H:%M:%S'): # the seconds since epoch, as suggested on stackoverflow: # http://stackoverflow.com/questions/1697815 return datetime.datetime.fromtimestamp(time.mktime(time_struct)) + + def test_job_name_cleaning(self): + """Test that invalid characters are cleaned from job name.""" + from aiida.schedulers.datastructures import JobTemplate + + scheduler = SgeScheduler() + + job_tmpl = JobTemplate() + job_tmpl.job_resource = scheduler.create_job_resource(parallel_env='mpi8', tot_num_mpiprocs=16) + job_tmpl.job_name = 'Some/job:name@with*invalid-characters.' + + header = scheduler._get_submit_script_header(job_tmpl) + self.assertTrue('#$ -N Somejobnamewithinvalid-characters.' in header, header)