Skip to content

refactor(sessions): move blocked_status_codes from Session to crawler - #2160

Draft
aryansk wants to merge 1 commit into
apify:masterfrom
aryansk:refactor/2139-move-blocked-status-codes
Draft

refactor(sessions): move blocked_status_codes from Session to crawler#2160
aryansk wants to merge 1 commit into
apify:masterfrom
aryansk:refactor/2139-move-blocked-status-codes

Conversation

@aryansk

@aryansk aryansk commented Aug 15, 2026

Copy link
Copy Markdown

Closes #2139

What

blocked_status_codes was configured per Session even though deciding whether a response means "blocked" is the crawler's concern — the crawler already owns additional_http_error_status_codes and ignore_http_error_status_codes. This moves it to a crawler option and keeps the handling internal to the crawler, matching the JS implementation (apify/crawlee#3496).

Changes

  • BasicCrawler gains a blocked_status_codes option, defaulting to [401, 403, 429]. The blocked-status check in _raise_for_session_blocked_status_code now consults self._blocked_status_codes - self._ignore_http_error_status_codes instead of asking the Session.
  • Session drops the blocked_status_codes parameter, the is_blocked_status_code() method, and the internal set; get_state() no longer serializes the field.
  • SessionModel drops the blockedStatusCodes field.
  • Docs: the session-management and error-handling examples now configure blocked_status_codes on the crawler instead of inside Session / create_session_settings.
  • Tests: session and model tests updated for the removed field; new crawler tests cover the default set, a custom set, and the ignore_http_error_status_codes interaction.

Validation

  • ruff check and ruff format --check clean
  • ty check clean on the touched modules
  • Unit suites pass: tests/unit/sessions/ (29) and tests/unit/crawlers/_basic/ + _http/ (196, 1 pre-existing skip)

Deciding whether a response status means "blocked" is the crawler's
concern, not the session's - the crawler already owns
additional_http_error_status_codes and ignore_http_error_status_codes.
Move blocked status code handling out of Session/SessionPool and onto
BasicCrawler, matching the JS implementation (apify/crawlee#3496).

- BasicCrawler gains a `blocked_status_codes` option (default
  [401, 403, 429]); the blocked check in
  _raise_for_session_blocked_status_code now consults the crawler's set
  minus ignore_http_error_status_codes instead of Session
- Session drops the blocked_status_codes parameter, the
  is_blocked_status_code method, and the model field; get_state no
  longer serializes it
- docs: session examples configure blocked_status_codes on the crawler
- tests: session/model tests updated; new crawler tests cover the
  default set, custom values, and ignore-code interaction

Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
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

Successfully merging this pull request may close these issues.

Move blocked_status_codes from Session to the crawler

2 participants