Skip to content

fix: don't disable Actor exit_process just because scrapy is importable#1049

Open
vdusek wants to merge 5 commits into
masterfrom
worktree-fix-b7
Open

fix: don't disable Actor exit_process just because scrapy is importable#1049
vdusek wants to merge 5 commits into
masterfrom
worktree-fix-b7

Conversation

@vdusek

@vdusek vdusek commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

_get_default_exit_process decided the exit_process default from whether import scrapy succeeded, not from whether the Actor is actually running under Scrapy. Any image where Scrapy arrives as a transitive dependency therefore silently disabled the sys.exit() on Actor exit. On the platform, an Actor that signals failure via Actor.fail(exit_code=1) without raising would keep running, end with exit code 0, and get marked SUCCEEDED.

Detection now lives in apify.scrapy._detection and treats the Actor as running under Scrapy when either of these holds:

  • run_scrapy_actor is driving the process. It sets an explicit flag before the Actor's main coroutine runs, hence before the Actor initializes.
  • The SCRAPY_SETTINGS_MODULE environment variable is set, by the Scrapy CLI or the Actor's entry point. This is the fallback and is already documented as a detection mechanism.

_actor.py consults this detector only through sys.modules, so a non-Scrapy Actor never imports apify.scrapy. Importing it pulls in Scrapy itself (~860 ms), and the old importability check would disable exit_process for exactly such images.

Test environments no longer get exit_process=False implicitly through the scrapy import. The unit _isolate_test_environment fixture now forces the default to False explicitly, since production code must not detect the test environment (see #641). As a side effect, the unit suite no longer needs the scrapy extra installed to avoid SystemExit.

Behavioral change: an Actor that runs Scrapy without using run_scrapy_actor and without setting SCRAPY_SETTINGS_MODULE now defaults exit_process to True. The documented Scrapy setup and the project template always do at least one of those, so legitimate Scrapy Actors are unaffected. I kept this as a plain fix: rather than a breaking change since the old behavior was itself the bug; promote the squash title to fix!: at merge if a major bump is preferred.

@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Jul 15, 2026
@vdusek vdusek self-assigned this Jul 15, 2026
@github-actions github-actions Bot added this to the 145th sprint - Tooling team milestone Jul 15, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Jul 15, 2026
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.79%. Comparing base (573e3a3) to head (0f4ebb3).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/apify/scrapy/_actor_runner.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1049      +/-   ##
==========================================
+ Coverage   91.77%   91.79%   +0.02%     
==========================================
  Files          50       51       +1     
  Lines        3222     3231       +9     
==========================================
+ Hits         2957     2966       +9     
  Misses        265      265              
Flag Coverage Δ
e2e 35.37% <16.66%> (-0.20%) ⬇️
integration 57.13% <16.66%> (-0.23%) ⬇️
unit 83.16% <91.66%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek vdusek requested a review from Pijukatel July 16, 2026 10:44
@vdusek vdusek marked this pull request as ready for review July 16, 2026 10:44
@vdusek vdusek requested a review from szaganek as a code owner July 16, 2026 10:44
# Conflicts:
#	tests/unit/actor/test_actor_lifecycle.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants