From b44ae85a8d9e81041c949a380193b1999ed7759b Mon Sep 17 00:00:00 2001 From: Uriel Sandoval Date: Sat, 9 Nov 2024 01:03:55 -0600 Subject: [PATCH] Adds validation to avoid ":" when user pass job_id (#2138) --- rq/job.py | 4 ++++ tests/test_job.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/rq/job.py b/rq/job.py index 918f7fdc..7a964aef 100644 --- a/rq/job.py +++ b/rq/job.py @@ -729,6 +729,10 @@ class Job: """ if not isinstance(value, str): raise TypeError('id must be a string, not {0}'.format(type(value))) + + if ":" in value: + raise ValueError('id must not contain ":"') + self._id = value def heartbeat(self, timestamp: datetime, ttl: int, pipeline: Optional['Pipeline'] = None, xx: bool = False): diff --git a/tests/test_job.py b/tests/test_job.py index 36c356e5..9f93cfbf 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -900,6 +900,13 @@ class TestJob(RQTestCase): self.assertRaises(TypeError, queue.enqueue, fixtures.say_hello, job_id=1234) + def test_create_job_with_invalid_id(self): + """test creating jobs with a custom invalid ID (with character :)""" + queue = Queue(connection=self.connection) + + with self.assertRaises(ValueError): + queue.enqueue(fixtures.say_hello, job_id="1234:4321") + def test_create_job_with_async(self): """test creating jobs with async function""" queue = Queue(connection=self.connection)