Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent kwargs override on replace #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sushinoya
Copy link

Background

In scrapy's Request class, the following function is defined -

    def replace(self, *args, **kwargs):
        """Create a new Request with the same attributes except for those
        given new values.
        """
        for x in ['url', 'method', 'headers', 'body', 'cookies', 'meta', 'flags',
                  'encoding', 'priority', 'dont_filter', 'callback', 'errback', 'cb_kwargs']:
            kwargs.setdefault(x, getattr(self, x))
        cls = kwargs.pop('cls', self.__class__)
        return cls(*args, **kwargs)

Since, SeleniumRequest inherits from Request, when .replace() is called upon a SelemiunRequest object, it defers to its super class. And as we can see in the snippet above, a new Request is constructed using only a select few attributes. These attributes do not include SeleniumRequest's additional ones such as wait_time and wait_until. Thus, after a replace call, these attributes are set to None which can lead to all sorts of errors and unexpected behavior.

This PR fixes that issue.

@gsi-luis
Copy link

Hi, this PR is very important for me, is it possible to review and merge? I tested in scrapy v1.6.0 and v2.9.0 and the issue persist :). I working many days to identified was happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants