diff --git a/src/apify/scrapy/scheduler.py b/src/apify/scrapy/scheduler.py index 258d11d9..96a5386b 100644 --- a/src/apify/scrapy/scheduler.py +++ b/src/apify/scrapy/scheduler.py @@ -193,7 +193,7 @@ def close(self, reason: str) -> None: if outcome is not None: logger.error( 'Failed to reclaim the request %s in the request queue.', - apify_request, + apify_request.unique_key, exc_info=outcome, ) @@ -311,7 +311,7 @@ def next_request(self) -> Request | None: scrapy_request = to_scrapy_request(apify_request, spider=self.spider) except Exception as exc: logger.warning( - 'Failed to convert Apify request %s to a Scrapy request; skipping it: %s', apify_request, exc + 'Failed to convert Apify request %s to a Scrapy request; skipping it: %s', apify_request.unique_key, exc ) try: self._async_thread.run_coro(self._rq.mark_request_as_handled(apify_request)) @@ -505,7 +505,7 @@ def _failed_marks( if outcome is not None: logger.error( 'Failed to mark the request %s as handled in the request queue.', - apify_request, + apify_request.unique_key, exc_info=outcome, ) failed.append((apify_request, scrapy_request)) diff --git a/tests/unit/scrapy/test_scheduler.py b/tests/unit/scrapy/test_scheduler.py index e6a7a8f1..17b3f98d 100644 --- a/tests/unit/scrapy/test_scheduler.py +++ b/tests/unit/scrapy/test_scheduler.py @@ -222,6 +222,7 @@ def test_next_request_skips_request_that_fails_to_convert( # The malformed request is skipped instead of crashing the whole run. assert result is None assert 'skipping it' in caplog.text + assert 'this is not a correctly encoded Scrapy request' not in caplog.text # Even though conversion failed, the unrecoverable entry is still marked as handled (consumed), so # the queue does not keep handing it back forever. @@ -422,6 +423,9 @@ def test_close_reclaims_the_other_requests_after_a_failed_reclaim( assert rq.reclaim_request.call_count == 2 errors = [record for record in caplog.records if record.levelno >= logging.ERROR] assert len(errors) == 1 + assert errors[0].getMessage() == ( + f'Failed to reclaim the request {APIFY_REQUESTS[0].unique_key} in the request queue.' + ) def test_close_reaches_the_rq_in_one_round_trip_per_operation( @@ -470,6 +474,9 @@ def test_a_failed_mark_keeps_the_request_tracked( assert scheduler._requests_in_flight errors = [record for record in caplog.records if record.levelno >= logging.ERROR] assert len(errors) == 1 + assert errors[0].getMessage() == ( + f'Failed to mark the request {APIFY_REQUESTS[0].unique_key} as handled in the request queue.' + ) def test_a_mark_that_fails_after_being_fired_off_is_retried(