Commit b0b7df7
authored
fix(scrapy): Avoid mutating request userData during Scrapy-Apify conversion (#978)
`to_apify_request` serialized the Scrapy request **after**
`Request.from_url()` had mutated the shared `meta['userData']` dict
(same bug class as #832).
`Request.from_url()` injects a live `CrawleeRequestData` object under
`__crawlee` into the very `user_data` dict it receives — which was the
spider's own `meta['userData']`. Because `scrapy_request.to_dict()` ran
afterward, two things went wrong:
- the spider's own request `meta['userData']` was mutated in place, and
- the serialized `scrapy_request` blob stored on the platform embedded
redundant Crawlee internals in every request.
**Fix:** capture `scrapy_request.to_dict()` *before* calling
`from_url()`, and pass `from_url()` a copy of `user_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.1 parent 53122e4 commit b0b7df7
2 files changed
Lines changed: 35 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
86 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
87 | 96 | | |
88 | 97 | | |
| 98 | + | |
| 99 | + | |
89 | 100 | | |
90 | 101 | | |
91 | 102 | | |
| |||
117 | 128 | | |
118 | 129 | | |
119 | 130 | | |
120 | | - | |
121 | 131 | | |
122 | 132 | | |
123 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
143 | 166 | | |
144 | 167 | | |
145 | 168 | | |
| |||
0 commit comments