fix: Avoid mutating Scrapy request userData during conversion#978
Draft
vdusek wants to merge 2 commits into
Draft
fix: Avoid mutating Scrapy request userData during conversion#978vdusek wants to merge 2 commits into
vdusek wants to merge 2 commits into
Conversation
`Request.from_url()` injects a live `CrawleeRequestData` into the `user_data` dict it receives, which was the spider's own `meta['userData']`. Serialize the Scrapy request before `from_url()` and pass it a copy so the spider's request stays untouched and the stored blob is free of redundant Crawlee internals.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #978 +/- ##
=======================================
Coverage 89.90% 89.91%
=======================================
Files 49 49
Lines 3091 3093 +2
=======================================
+ Hits 2779 2781 +2
Misses 312 312
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:
|
…user-data-mutation
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.
to_apify_requestserialized the Scrapy request afterRequest.from_url()had mutated the sharedmeta['userData']dict (same bug class as #832).Request.from_url()injects a liveCrawleeRequestDataobject under__crawleeinto the veryuser_datadict it receives — which was the spider's ownmeta['userData']. Becausescrapy_request.to_dict()ran afterward, two things went wrong:meta['userData']was mutated in place, andscrapy_requestblob stored on the platform embedded redundant Crawlee internals in every request.Fix: capture
scrapy_request.to_dict()before callingfrom_url(), and passfrom_url()a copy ofuser_data(dict(user_data)for the plain-dict branch;model_dump()already returns a fresh dict). The spider's request stays untouched and the stored blob is free of injected Crawlee data.Added two regression tests covering both the no-mutation guarantee and the clean serialized blob.