fix(scrapy): make logging configuration idempotent#954
Open
vdusek wants to merge 4 commits into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #954 +/- ##
==========================================
- Coverage 90.00% 89.84% -0.17%
==========================================
Files 49 49
Lines 3053 3062 +9
==========================================
+ Hits 2748 2751 +3
- Misses 305 311 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Pijukatel
reviewed
Jun 9, 2026
| logger.propagate = False | ||
|
|
||
|
|
||
| def _configure_all_loggers() -> None: |
Contributor
There was a problem hiding this comment.
Maybe I am missing some context, but can't we skip the module-level dict and do it like this?
@lru_cache
def _configure_all_loggers(handler, level):
if handler is None:
return
for logger_name in [None, *_ALL_LOGGERS]:
_configure_logger(logger_name, level, handler)
Contributor
Author
There was a problem hiding this comment.
Unfortunately, we can't do that - the _configure_all_loggers needs to run more than once.
The expected flow of the Scrapy Actors is something like this:
- We configure logging (our handler + levels).
- We do some setup, during which things may already log.
- Scrapy's own setup runs and overrides our logging configuration.
- We re-apply our configuration on top to override it back.
So the current code is the correct way.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
initialize_loggingre-wrappedscrapy.utils.log.configure_loggingon every call, stacking wrappers when it ran more than once. The monkey-patch is now installed at most once and reads the current handler and level from a module-level state dict, so repeated initialization stays correct without nesting wrappers.Part of splitting the larger Scrapy integration fix (
fix/scrapy-integration) into reviewable pieces.