Skip to content

Commit 55326a4

Browse files
committed
Implement dependency resolution
1 parent 596431b commit 55326a4

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

scrapy_poet/_request_fingerprinter.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,10 @@ def _get_deps(self, request: Request) -> Optional[List[str]]:
100100
dependencies requested by the request, or None if dependency injection
101101
is not required."""
102102
plan = self._injector.build_plan(request)
103-
root_deps = plan[-1][1]
104-
if not root_deps:
103+
deps = {dep for dep, params in plan[:-1]} - self.IGNORED_UNANNOTATED_DEPS
104+
if not deps:
105105
return None
106-
return sorted(
107-
[
108-
_serialize_dep(cls)
109-
for cls in root_deps.values()
110-
if cls not in self.IGNORED_UNANNOTATED_DEPS
111-
]
112-
)
106+
return sorted([_serialize_dep(cls) for cls in deps])
113107

114108
def get_deps_key(self, request: Request) -> Optional[bytes]:
115109
"""Return a JSON array as bytes that uniquely identifies the

tests/test_request_fingerprinter.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,6 @@ async def parse_all(self, response, input_a: input_cls_a, input_b: input_cls_b):
305305

306306

307307
def test_dep_resolution():
308-
"""Currently we do not resolve dependencies, so it is possible to get a
309-
different fingerprint for callbacks that resolve to identical
310-
dependencies.
311-
312-
The reason for not resolving dependencies is that it could be hard where
313-
items are involved. This might be addressed in the future, in which case
314-
we should consider to fingerprint based on leaf dependencies (those with a
315-
provider) and not on the root dependencies present in the callback.
316-
"""
317-
318308
class TestSpider(Spider):
319309
name = "test_spider"
320310

@@ -330,7 +320,7 @@ async def parse_b(self, response, web: WebPage, http_response: HttpResponse):
330320
fingerprint1 = fingerprinter.fingerprint(request1)
331321
request2 = Request("https://toscrape.com", callback=crawler.spider.parse_b)
332322
fingerprint2 = fingerprinter.fingerprint(request2)
333-
assert fingerprint1 != fingerprint2
323+
assert fingerprint1 == fingerprint2
334324

335325

336326
def test_page_params(caplog):

0 commit comments

Comments
 (0)