fix: preserve preconfigured logging#755
Conversation
Signed-off-by: schultzjack <schultzjack@users.noreply.github.com>
|
All contributors have signed the DCO ✍️ ✅ |
Greptile SummaryThis PR fixes issue #388 by preventing
|
| Filename | Overview |
|---|---|
| packages/data-designer-config/src/data_designer/logging.py | Adds module-level _logging_configured flag, sets it at the end of configure_logging(), and exposes is_logging_configured(). Logic is correct; the flag is set only after all side-effects succeed. |
| packages/data-designer/src/data_designer/interface/data_designer.py | Adds auto_configure_logging keyword-only parameter to DataDesigner.__init__ and threads it through _initialize_interface_runtime; guard condition correctly combines both signals before calling configure_logging(). |
| packages/data-designer-config/tests/test_logging.py | Adds one test verifying that configure_logging() sets the _logging_configured flag; properly uses monkeypatch to reset the flag before and after. |
| packages/data-designer/tests/interface/test_data_designer.py | Adds five new regression tests covering all combinations of pre-configured logging, auto_configure_logging=False, and default construction; existing test patched to also reset _logging_configured for correct isolation. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["DataDesigner.__init__(auto_configure_logging=...)"] --> B["_initialize_interface_runtime(auto_configure_logging=...)"]
B --> C{"_interface_runtime_initialized?"}
C -- "Yes" --> Z["return (no-op)"]
C -- "No" --> D{"auto_configure_logging AND NOT is_logging_configured()"}
D -- "True" --> E["configure_logging()"]
E --> F["_logging_configured = True"]
F --> G["resolve_seed_default_model_settings()"]
D -- "False" --> G
G --> H["_interface_runtime_initialized = True"]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["DataDesigner.__init__(auto_configure_logging=...)"] --> B["_initialize_interface_runtime(auto_configure_logging=...)"]
B --> C{"_interface_runtime_initialized?"}
C -- "Yes" --> Z["return (no-op)"]
C -- "No" --> D{"auto_configure_logging AND NOT is_logging_configured()"}
D -- "True" --> E["configure_logging()"]
E --> F["_logging_configured = True"]
F --> G["resolve_seed_default_model_settings()"]
D -- "False" --> G
G --> H["_interface_runtime_initialized = True"]
Reviews (3): Last reviewed commit: "Merge branch 'main' into codex/388-prese..." | Re-trigger Greptile
|
recheck |
Stale PR reminderThis PR has had failing checks for 7 days without activity. Failing checks: check Please push an update or leave a comment if you're still working on this. To prevent auto-close, add the |
|
Issue #388 has been triaged. The linked issue check is being re-evaluated. |
|
Thanks for jumping on this, this fixes a pretty easy-to-miss logging footgun. I reviewed the runtime init path and the new logging state tracking. The core behavior looks good, but I'd like one small clarification before merge.
Please add a short docstring/comment making that scope explicit, or broaden the check if you want this to cover general Python logging setup too. The current fix is fine for the linked issue, but the helper name reads a bit broader than what it actually guarantees. Focused tests and a smoke check passed locally. Once that expectation is tightened up, this looks good to merge from my side. |
|
Following up on my comment above: the current fix handles the narrow repro from #388 where the caller uses There is a related case discussed later in #388 that this does not cover yet: applications that configure logging through stdlib APIs before using Data Designer. For example, if a caller uses I think the lowest-risk incremental direction is to make DD's automatic runtime logging setup opt-out explicitly, which also matches the direction Mike suggested on #388. Something like:
That should keep standalone behavior unchanged while giving embedded/library users a reliable way to prevent DD from taking over process logging. |
…configured-logging
Address review feedback on NVIDIA-NeMo#755 and the embedding case from NVIDIA-NeMo#388: - document that is_logging_configured() only tracks Data Designer's own configure_logging(), not stdlib logging configuration - add auto_configure_logging keyword to DataDesigner.__init__ so applications that manage their own logging (e.g. via logging.basicConfig()) can opt out of Data Designer's default logging setup - add tests for the default behavior, the opt-out preserving existing root handlers, and prior configure_logging() still being preserved Signed-off-by: schultzjack <schultzjack@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks for the careful pass, and for spelling out the direction in the follow-up — having the acceptance criteria written out made this straightforward. Both points addressed in 4b5a6b0.
Tests cover the three cases you listed: default construction still configures DD logging, Also verified both repros from #388 locally: the original MRE (DEBUG level survives Branch is synced with main. |
andreatgretel
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. The logging configuration scope is now explicit, auto_configure_logging=False provides the requested opt-out, and the default, preconfigured, and opt-out paths are covered. I don't see any remaining blockers. Approving.
nabinchha
left a comment
There was a problem hiding this comment.
Thanks for tackling this, @schultzjack — really clean fix for an annoying footgun, and the coverage (default, preconfigured, and the auto_configure_logging=False opt-out preserving real root handlers) is thorough. The explicit docstring about is_logging_configured() only tracking Data Designer's own configure_logging() is a nice touch.
Approving to unblock merge.
I've filed #805 to track a follow-up cleanup: replacing the _logging_configured / _interface_runtime_initialized module globals with observable state, adding a public reset_logging(), and dropping the private-global patching from these tests (which also makes auto_configure_logging take effect per-instance rather than only on the first construction). That's intentionally scoped out of this PR so we can land the fix now.
Summary
auto_configure_loggingkeyword toDataDesigner.__init__so applications that manage their own logging (e.g. vialogging.basicConfig()or custom root handlers) can opt out of Data Designer's default logging setup entirelyis_logging_configured()only tracks Data Designer's ownconfigure_logging(), not stdlib logging configurationauto_configure_logging=Falsepreserving existing root handlersTesting
logging.basicConfig()handlers/formatters surviveDataDesigner(auto_configure_logging=False)Closes #388