Skip to content

Commit

Permalink
[spiders] Remove 'spider' argument to ExecutionEngine.crawl (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
mic1on authored Nov 26, 2023
1 parent 937c537 commit 48a7a89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/scrapy_redis/spiders.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from collections.abc import Iterable
from scrapy import signals, FormRequest
from scrapy import signals, FormRequest, version_info as scrapy_version
from scrapy.exceptions import DontCloseSpider
from scrapy.spiders import Spider, CrawlSpider
from scrapy_redis.utils import TextColor
Expand Down Expand Up @@ -190,7 +190,11 @@ def schedule_next_requests(self):
"""Schedules a request if available"""
# TODO: While there is capacity, schedule a batch of redis requests.
for req in self.next_requests():
self.crawler.engine.crawl(req, spider=self)
# see https://github.com/scrapy/scrapy/issues/5994
if scrapy_version >= (2, 6):
self.crawler.engine.crawl(req)
else:
self.crawler.engine.crawl(req, spider=self)

def spider_idle(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_spiders.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def test_consume_urls_from_redis(start_urls_as_zset, start_urls_as_set, spider_c

if start_urls_as_zset or start_urls_as_set:
crawler.engine.crawl.assert_has_calls([
mock.call(req, spider=spider) for req in reqs if req not in start_requests
mock.call(req) for req in reqs if req not in start_requests
], any_order=True)
else:
crawler.engine.crawl.assert_has_calls([
mock.call(req, spider=spider) for req in reqs[batch_size:]
mock.call(req) for req in reqs[batch_size:]
])

0 comments on commit 48a7a89

Please sign in to comment.