Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/apify/scrapy/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/scrapy/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down