Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail on SPM + transparent mode #152

Merged
merged 7 commits into from
Nov 30, 2023
Merged

Fail on SPM + transparent mode #152

merged 7 commits into from
Nov 30, 2023

Conversation

Gallaecio
Copy link
Contributor

I went with raising NotConfigured from the handlers.

However, I wonder if instead we should treat this as a fatal error and close the spider with a custom reason.

In fact, I wonder if we should do that for other NotConfigured errors in the handler, since some users have a hard time figuring out those kind of issues from the logs, and a non-working HTTP/HTTPS handler feels like a critical-enough issue to warrant closing the spider until it is addressed.

Copy link

codecov bot commented Nov 23, 2023

Codecov Report

Merging #152 (369c97b) into main (dc09ac3) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #152      +/-   ##
==========================================
+ Coverage   98.89%   98.94%   +0.04%     
==========================================
  Files          10       10              
  Lines         724      756      +32     
==========================================
+ Hits          716      748      +32     
  Misses          8        8              
Files Coverage Δ
scrapy_zyte_api/_middlewares.py 100.00% <100.00%> (ø)

@@ -62,6 +62,29 @@ def __init__(
raise NotConfigured(
"Zyte API is disabled. Set ZYTE_API_ENABLED to True to enable it."
)
if settings.getbool("ZYTE_API_TRANSPARENT_MODE", False) and (
settings.getbool("ZYTE_SMARTPROXY_ENABLED", False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to disable SPM using spider attributes; how do we handle this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we move this to a signal handler for spider_opened, where we can check the spider as well, and close the spider from there in this scenario?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I think there is also a middleware method (is_enabled?) which can be useful, but I haven't really checked it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gallaecio Gallaecio merged commit d701f48 into main Nov 30, 2023
19 checks passed
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.

4 participants