fix!: use Scrapy's fingerprint for Scrapy request unique keys#1047
Closed
vdusek wants to merge 2 commits into
Closed
fix!: use Scrapy's fingerprint for Scrapy request unique keys#1047vdusek wants to merge 2 commits into
vdusek wants to merge 2 commits into
Conversation
BREAKING CHANGE: Unique keys for requests converted from Scrapy are now derived from Scrapy's own request fingerprint (case-sensitive URL, `utm_*` params kept, headers ignored) instead of Crawlee's URL normalization (which lowercased the whole URL and stripped `utm_*`). Requests that vanilla Scrapy treats as distinct are no longer silently deduplicated away. Request queues keyed under the old normalized-URL scheme will not deduplicate new requests against pre-existing entries after upgrading.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1047 +/- ##
=======================================
Coverage 91.75% 91.76%
=======================================
Files 50 50
Lines 3215 3218 +3
=======================================
+ Hits 2950 2953 +3
Misses 265 265
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Scrapy's deduplication doesn't handle two things that matter for scraping:
Based on these findings, I've decided to stay with the Apify (Crawlee) deduplication system. Closing this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When converting a Scrapy request to an Apify request,
to_apify_requestcomputed the request queue unique key via Crawlee'sRequest.from_url(use_extended_unique_key=True). Crawlee'snormalize_urllowercases the whole URL and stripsutm_*params, and the extended key hashes a whitelist of headers. Scrapy's own deduplication (RFPDupeFilter) instead uses a fingerprint that canonicalizes the URL case-sensitively (w3lib.url.canonicalize_url), keepsutm_*, and ignores headers.The two disagreed in both directions:
/Products/Item-Aand/products/item-a(and?utm_source=x&id=1vs?id=1) collapsed onto the same unique key, so sites with case-sensitive paths (S3-backed, Django) silently lost pages vanilla Scrapy crawls; meanwhile requests differing only in headers Scrapy ignores were over-split into separate entries.to_apify_requestnow derives the unique key from Scrapy's request fingerprint (spider.crawler.request_fingerprinter.fingerprint(request).hex(), honoring a customREQUEST_FINGERPRINTER_CLASS, with a fallback to the default fingerprinter when the spider is not bound to a crawler), matchingRFPDupeFiltersemantics. Thedont_filter(always-enqueue) and explicitapify_request_unique_key(roundtrip continuity) paths are unchanged.Breaking change
Unique keys for converted Scrapy requests change value. A run resuming against a request queue that was populated by an older SDK version will not deduplicate new requests against the pre-existing entries, so some already-seen URLs may be re-enqueued once. New queues and fresh runs are unaffected.