Adds validation to avoid ":" when user pass job_id (#2138)

This commit is contained in:
Uriel Sandoval 2024-11-09 01:03:55 -06:00 committed by GitHub
parent bb7f340537
commit b44ae85a8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -729,6 +729,10 @@ class Job:
""" """
if not isinstance(value, str): if not isinstance(value, str):
raise TypeError('id must be a string, not {0}'.format(type(value))) raise TypeError('id must be a string, not {0}'.format(type(value)))
if ":" in value:
raise ValueError('id must not contain ":"')
self._id = value self._id = value
def heartbeat(self, timestamp: datetime, ttl: int, pipeline: Optional['Pipeline'] = None, xx: bool = False): def heartbeat(self, timestamp: datetime, ttl: int, pipeline: Optional['Pipeline'] = None, xx: bool = False):

View File

@ -900,6 +900,13 @@ class TestJob(RQTestCase):
self.assertRaises(TypeError, queue.enqueue, fixtures.say_hello, job_id=1234) 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): def test_create_job_with_async(self):
"""test creating jobs with async function""" """test creating jobs with async function"""
queue = Queue(connection=self.connection) queue = Queue(connection=self.connection)