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

Job.get_status() does not always return JobStatus Enum #2038

Open
indepndnt opened this issue Feb 9, 2024 · 0 comments
Open

Job.get_status() does not always return JobStatus Enum #2038

indepndnt opened this issue Feb 9, 2024 · 0 comments

Comments

@indepndnt
Copy link

As it is, the return type for get_status is Union[JobStatus, str, None]. This results in an error if you expect an Enum and call Job.get_status().value.

I believe the return type annotations in line 325 and 332 should be Optional[JobStatus] and line 336 should be updated to self._status = JobStatus(as_text(status)) if status else None.

rq/rq/job.py

Lines 325 to 337 in 2f5fecc

def get_status(self, refresh: bool = True) -> JobStatus:
"""Gets the Job Status
Args:
refresh (bool, optional): Whether to refresh the Job. Defaults to True.
Returns:
status (JobStatus): The Job Status
"""
if refresh:
status = self.connection.hget(self.key, 'status')
self._status = as_text(status) if status else None
return self._status

Also line 950 in Job.restore should probably be self._status = JobStatus(as_text(obj.get('status'))) if obj.get('status') else None for consistency and so that it doesn't set Job._status to a string.

rq/rq/job.py

Line 950 in 2f5fecc

self._status = obj.get('status').decode() if obj.get('status') else None

I also noticed that the docstring for the as_text function is inconsistent, it should probably say value (str): The decoded string.

rq/rq/utils.py

Lines 41 to 52 in 2f5fecc

def as_text(v: Union[bytes, str]) -> str:
"""Converts a bytes value to a string using `utf-8`.
Args:
v (Union[bytes, str]): The value (bytes or string)
Raises:
ValueError: If the value is not bytes or string
Returns:
value (Optional[str]): Either the decoded string or None
"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant