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
CallbackKeywordArgumentsContract #3988
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3988 +/- ##
==========================================
- Coverage 85.39% 85.38% -0.02%
==========================================
Files 167 167
Lines 9724 9730 +6
Branches 1456 1456
==========================================
+ Hits 8304 8308 +4
- Misses 1162 1164 +2
Partials 258 258
|
scrapy/contracts/__init__.py
Outdated
@@ -92,7 +92,7 @@ def _clean_req(self, request, method, results): | |||
@wraps(cb) | |||
def cb_wrapper(response): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're wrapping the callback, you need to receive the kwargs
here as well.
@wraps(cb)
def cb_wrapper(response, **cb_kwargs):
pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to do it in the other wrappers.
scrapy/contracts/__init__.py
Outdated
@@ -92,7 +92,7 @@ def _clean_req(self, request, method, results): | |||
@wraps(cb) | |||
def cb_wrapper(response): | |||
try: | |||
output = cb(response) | |||
output = cb(response, **request.cb_kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, instead of using the synthetic request's kwargs
, you need to pass the wrapped kwargs
to the callback.
try:
output = cb(response, **cb_kwargs)
except Exception:
...
Despite of that, you might have some problems when trying to pass a Python object through the |
That's true, but it's a current limitation of |
Thanks @elacuesta, and thanks @victor-torres and @Gallaecio for reviews! |
Fixes #3985
This patch works partially, in the sense that it prevents the reportedTypeError
(I checked, for instance by adding a simpleprint(request.cb_kwargs)
to https://github.com/scrapy/scrapy/blob/1.7.3/scrapy/core/scheduler.py#L90, and the generated request does include a validcb_kwargs
attribute). However, adding the@cb_kwargs
contract causes the whole callback to be excluded from the tests, and I can't for the life of me figure out why.Update: Working now, thanks to @victor-torres🚀
Remaining tasks: