From 4b2fa947a15db8bb2da6d6d01d7bbeb19bb74f10 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 2 Oct 2023 11:44:05 +0200 Subject: [PATCH] RQ changed how the set jobs to failed. Dealing with this. --- sentry_sdk/integrations/rq.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/rq.py b/sentry_sdk/integrations/rq.py index 5596fe6acf..7f1a79abed 100644 --- a/sentry_sdk/integrations/rq.py +++ b/sentry_sdk/integrations/rq.py @@ -20,6 +20,7 @@ from rq.timeouts import JobTimeoutException from rq.version import VERSION as RQ_VERSION from rq.worker import Worker + from rq.job import JobStatus except ImportError: raise DidNotEnable("RQ not installed") @@ -95,7 +96,9 @@ def sentry_patched_perform_job(self, job, *args, **kwargs): def sentry_patched_handle_exception(self, job, *exc_info, **kwargs): # type: (Worker, Any, *Any, **Any) -> Any - if job.is_failed: + # Note, the order of the `or` here is important, + # because calling `job.is_failed` will change `_status`. + if job._status == JobStatus.FAILED or job.is_failed: _capture_exception(exc_info) # type: ignore return old_handle_exception(self, job, *exc_info, **kwargs)