crawlee icon indicating copy to clipboard operation
crawlee copied to clipboard

transformRequestFunction returning null is ignored when enqueueLinks is called from the crawling context

Open nikitachapovskii-dev opened this issue 4 months ago • 0 comments

The RequestTransform type says the callback may return RequestOptions | false | undefined | null, and any falsy value should skip the request. That holds if you call enqueueLinks from crawlee directly, but not if you call context.enqueueLinks inside a request handler. There, null and undefined are turned back into the original request and the URL is enqueued anyway. false still works.

Repro (3.16.0 and 3.17.0):

await enqueueLinks({
    strategy: 'all',
    transformRequestFunction: () => null, // reject everything
});
// expected: nothing enqueued
// actual: every link is enqueued

Change null to false and it behaves as documented.

From claude:

The wrapper was added in 3.14.0 but had no effect there, because the object literal ended with ...options and that overwrote the key. #3159 reordered the spread, so from 3.15.0 the wrapper always applies and the bug became reachable. It is still there in 3.17.0 and in 4.0.0-beta.

Proposed fix: In enqueueLinksWithCrawlDepth separate "no transform provided" from "transform returned falsy" and pass the return value through, so the existing falsy check inside enqueueLinks handles it:

if (!options.transformRequestFunction) {
    return newRequest;
}

return options.transformRequestFunction(newRequest);

Happy to open a PR if this looks reasonable.

nikitachapovskii-dev avatar Jul 28 '26 13:07 nikitachapovskii-dev