Skip to content

Conversation

@haakonvt
Copy link
Contributor

@haakonvt haakonvt commented Dec 22, 2025

Description

https://cognitedata.atlassian.net/browse/DM-3439

In the SDK, we accept the “debug: bool = False” parameter, which also can be turned on or off later. It has 2 main issues:

1. Critical Issue: The "Silent Logger" Bug

_disable_debug_logging() leaves the logger in a broken state.

The Flow:

  1. _configure_logger_for_debug_mode() sets logger.propagate = False.
  2. _disable_debug_logging() clears all handlers (logger.handlers = []) but does not reset propagate to True.

The Result: After you enable and then disable debug mode, the logger has no handlers and does not propagate to the root logger. Any subsequent logs (even errors or warnings) will be silently swallowed and effectively lost.

Fix: Restore propagation in the disable function.

2. High Risk: Direct List Manipulation

Directly assigning logger.handlers = [] is generally discouraged in Python logging for two reasons:

  1. Thread Safety: The logging module has internal locks. Modifying the list directly bypasses these safety mechanisms, which could cause race conditions in a multi-threaded application.
  2. Destructiveness: This wipes out any handler attached to that logger. If a user had manually attached a FileHandler to the Cognite logger to save logs to a disk, this function would silently delete it.

@haakonvt haakonvt requested review from a team as code owners December 22, 2025 09:50
@gemini-code-assist
Copy link
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@haakonvt haakonvt force-pushed the fix-propagate-is-false branch from 58b143f to e20a964 Compare December 22, 2025 09:54
@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 61.11111% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.33%. Comparing base (a2cc565) to head (90c1928).

Files with missing lines Patch % Lines
cognite/client/utils/_logging.py 61.11% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2429      +/-   ##
==========================================
+ Coverage   91.28%   91.33%   +0.04%     
==========================================
  Files         192      192              
  Lines       26184    26176       -8     
==========================================
+ Hits        23903    23907       +4     
+ Misses       2281     2269      -12     
Files with missing lines Coverage Δ
cognite/client/utils/_logging.py 77.50% <61.11%> (+23.33%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@haakonvt
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a critical bug where disabling debug logging would silence the logger entirely. The changes are well-implemented, replacing the unsafe direct manipulation of logger.handlers with the thread-safe addHandler and removeHandler methods, and correctly restoring log propagation. The refactoring of DebugLogFormatter is also a great improvement in simplicity and correctness. I've added a couple of suggestions to further enhance thread safety by iterating over a copy of the handlers list, which fully resolves the race condition concerns mentioned in the description.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

2 participants