scrapy: return in finally can swallow exception
Description
There are two places in scrapy/contracts/__init__.py where a finally: body contains a return statement, which would swallow any in-flight exception.
This means that if a BaseException (such as KeyboardInterrupt) is raised from the body, or any exception is raised from one of the except: clause, it will not propagate on as expected.
The pylint warning about this was suppressed in this commit but it doesn’t seem like there was justification for that.
These are the two locations: https://github.com/scrapy/scrapy/blame/b4bad97eae6bcce790a626d244c63589f4134408/scrapy/contracts/__init__.py#L56
See also https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (12 by maintainers)
Links to this issue
Commits related to this issue
- Fix: Remove return statements from finally blocks to prevent swallowing exceptions (#6505) — committed to rahulsamant37/scrapy by rahulsamant37 2 years ago
- Fix:Remove return statements from finally blocks to prevent swallowing exceptions (#6505) — committed to rahulsamant37/scrapy by rahulsamant37 2 years ago
- Fix: Remove return statements from finally blocks to prevent swallowing exceptions(#6505) — committed to rahulsamant37/scrapy by rahulsamant37 2 years ago
- Fix: Remove return statements from finally blocks to prevent swallowing exceptions(#6505) — committed to rahulsamant37/scrapy by rahulsamant37 2 years ago
- Fix:Remove return statements from finally blocks to prevent swallowing exceptions(#6505) — committed to rahulsamant37/scrapy by rahulsamant37 2 years ago
- Added failing test cases to tests/contracts.py where a keyboard interrupt will be swallowed inflight by return in finally block (#6505) — committed to nicklaustrup/scrapy by nicklaustrup 2 years ago
- Fix - return in finally can swallow exception (#6505) — committed to nicklaustrup/scrapy by nicklaustrup 2 years ago
- Merge pull request #6542 from nicklaustrup/Tests-contracts-swallowed-exceptions Fix - return in finally can swallow exception (#6505) — committed to scrapy/scrapy by wRAR 2 years ago
Here, specifically.
That’s unfortunate, especially as the way forward was already suggested earlier.