Skip to content

Commit f831b18

Browse files
vdusekclaude
andcommitted
fix: Remove deprecated spider arg from pipeline process_item methods
Scrapy 2.14+ deprecated the spider argument in process_item() and newer versions no longer pass it, causing TypeError in PriceCleanerPipeline. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent adf5fb2 commit f831b18

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

src/apify/scrapy/pipelines/actor_dataset_push.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from apify import Actor
99

1010
if TYPE_CHECKING:
11-
from scrapy import Item, Spider
11+
from scrapy import Item
1212

1313
logger = getLogger(__name__)
1414

@@ -22,10 +22,9 @@ class ActorDatasetPushPipeline:
2222
async def process_item(
2323
self,
2424
item: Item,
25-
spider: Spider,
2625
) -> Item:
2726
"""Pushes the provided Scrapy item to the Actor's default dataset."""
2827
item_dict = ItemAdapter(item).asdict()
29-
logger.debug(f'Pushing item={item_dict} produced by spider={spider} to the dataset.')
28+
logger.debug(f'Pushing item={item_dict} to the dataset.')
3029
await Actor.push_data(item_dict)
3130
return item

tests/e2e/test_scrapy/actor_source/pipelines.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
from typing import TYPE_CHECKING
44

55
if TYPE_CHECKING:
6-
from scrapy import Item, Spider
6+
from scrapy import Item
77

88

99
class PriceCleanerPipeline:
1010
def process_item(
1111
self,
1212
item: Item,
13-
_: Spider,
1413
) -> Item:
1514
if 'price' in item and isinstance(item['price'], str):
1615
item['price'] = item['price'].lstrip('$')

tests/unit/scrapy/pipelines/test_actor_dataset_push.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
from dataclasses import dataclass
44

55
import pytest
6-
from scrapy import Field, Item, Spider
6+
from scrapy import Field, Item
77

88
from apify import Actor
99
from apify.scrapy.pipelines import ActorDatasetPushPipeline
1010

1111

12-
class DummySpider(Spider):
13-
name = 'dummy_spider'
14-
15-
1612
class DummyItem(Item):
1713
a = Field()
1814
b = Field()
@@ -24,12 +20,6 @@ class TitleItem(Item):
2420
title = Field()
2521

2622

27-
@pytest.fixture
28-
def spider() -> DummySpider:
29-
"""Fixture to create a "dummy" Scrapy spider."""
30-
return DummySpider()
31-
32-
3323
@pytest.fixture
3424
def pipeline() -> ActorDatasetPushPipeline:
3525
"""Fixture to create an Actor dataset push pipeline."""
@@ -67,7 +57,6 @@ class ItemTestCase:
6757
async def test_process_item(
6858
monkeypatch: pytest.MonkeyPatch,
6959
pipeline: ActorDatasetPushPipeline,
70-
spider: Spider,
7160
tc: ItemTestCase,
7261
) -> None:
7362
dataset = []
@@ -79,9 +68,9 @@ async def mock_push_data(item: dict) -> None:
7968

8069
if tc.expected_exception:
8170
with pytest.raises(tc.expected_exception):
82-
await pipeline.process_item(tc.item, spider)
71+
await pipeline.process_item(tc.item)
8372

8473
else:
85-
output = await pipeline.process_item(tc.item, spider)
74+
output = await pipeline.process_item(tc.item)
8675
assert output == tc.item
8776
assert dataset == [tc.item_dict]

0 commit comments

Comments
 (0)