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

Fix The annoyning Deprecation issue in _middlewares.py #234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ahmed-ellaban
Copy link

@ahmed-ellaban ahmed-ellaban commented Dec 4, 2024

This pull request includes a change to the slot_request method in the scrapy_zyte_api/_middlewares.py file. The change involves modifying the way the slot key is obtained from the downloader.

  • scrapy_zyte_api/_middlewares.py: Changed the method call from downloader._get_slot_key(request, spider) to downloader.get_slot_key(request) to use the public method instead of a private one, and hide the warning log

Fixes #232

Fix The annoyning Deprecation issue
by just using get_slot_key instead of _get_slot_key and remove the second param
@@ -31,7 +31,7 @@ def slot_request(self, request, spider, force=False):
return

downloader = self._crawler.engine.downloader
slot_id = downloader._get_slot_key(request, spider)
slot_id = downloader.get_slot_key(request)
Copy link
Contributor

@Gallaecio Gallaecio Dec 9, 2024

Choose a reason for hiding this comment

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

We need to keep support for older versions of Scrapy as well:

Suggested change
slot_id = downloader.get_slot_key(request)
try:
slot_id = downloader.get_slot_key(request)
except AttributeError: # Scrapy < 2.12
slot_id = downloader._get_slot_key(request, spider)

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.

Switch to get_slot_key() when available
2 participants