Skip to content

fix(socket_mode): check the effective log level in debug guards - #1965

Open
Shubham-Padkonde wants to merge 1 commit into
slackapi:mainfrom
Shubham-Padkonde:fix/socket-mode-debug-guards
Open

Shubham-Padkonde wants to merge 1 commit into
slackapi:mainfrom
Shubham-Padkonde:fix/socket-mode-debug-guards

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

Fixes the Socket Mode part of #1957.

The debug guards compared logger.level, which stays NOTSET unless a level is set on that exact logger, so the guarded messages (including debug_redacted_message_string(message) for every inbound message) were built even when DEBUG was disabled through a parent logger. They now use isEnabledFor(logging.DEBUG), which follows the effective level.

I kept this to slack_sdk/socket_mode/; the same pattern in the other modules can follow separately if you want it project-wide.

The added test checks that the message is not built when a parent logger is at INFO and is built at DEBUG; it fails before this change. The Socket Mode test suites (sync and async), ruff and mypy pass.

🤖 Generated with Claude Code

The debug guards compared logger.level, which is NOTSET unless a level
is set on that exact logger, so the guarded messages were built even
when DEBUG is disabled through a parent logger. Use isEnabledFor(),
which follows the effective level.

Refs slackapi#1957

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Shubham-Padkonde
Shubham-Padkonde requested a review from a team as a code owner September 19, 2026 04:13
@AmyScript
AmyScript self-requested a review September 22, 2026 14:48
@codecov

codecov Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.15%. Comparing base (b9f4666) to head (7852bf0).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
slack_sdk/socket_mode/aiohttp/__init__.py 86.66% 2 Missing ⚠️
slack_sdk/socket_mode/websockets/__init__.py 81.81% 2 Missing ⚠️
slack_sdk/socket_mode/builtin/client.py 75.00% 1 Missing ⚠️
slack_sdk/socket_mode/websocket_client/__init__.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1965   +/-   ##
=======================================
  Coverage   84.15%   84.15%           
=======================================
  Files         118      118           
  Lines       13566    13566           
=======================================
  Hits        11416    11416           
  Misses       2150     2150           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@AmyScript AmyScript left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix. logger.level stays NOTSET (0) unless a level is set on that exact logger, so level <= DEBUG was effectively always true and the guarded strings (notably debug_redacted_message_string(message) on every inbound message) were built regardless of the effective level. isEnabledFor() follows getEffectiveLevel() and also respects logging.disable(). It's strictly safe too. Test genuinely fails before the change. LGTM. ✅

Non-blocking follow-ups (no need to hold this PR):

  • Worth a quick rg 'logger\.level\s*(<=|<|==)\s*logging\.' slack_sdk/socket_mode/
    just to confirm nothing in these modules slipped through.
  • Adding an async-path test case wouldn't hurt

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants