-
Notifications
You must be signed in to change notification settings - Fork 79
fix(interface): prevent configure_logging from being silently overwritten #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,7 +114,11 @@ def working() -> str: | |
| return random.choice(["⚙️", "🔧", "🔨", "⚒️", "🛠️", "💼", "👷", "🏗️", "🪛", "👨💻"]) | ||
|
|
||
|
|
||
| _configured = False | ||
|
|
||
|
|
||
| def configure_logging(config: LoggingConfig | None = None) -> None: | ||
| global _configured | ||
| config = config or LoggingConfig.default() | ||
|
|
||
| root_logger = logging.getLogger() | ||
|
|
@@ -137,6 +141,8 @@ def configure_logging(config: LoggingConfig | None = None) -> None: | |
| for name in config.to_silence: | ||
| quiet_noisy_logger(name) | ||
|
|
||
| _configured = True | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After In practice this doesn't cause a functional bug because the Consider documenting this clearly, or renaming the flag to Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/data-designer-config/src/data_designer/logging.py
Line: 144
Comment:
**`_configured` flag is set for runtime-initiated calls too**
After `_initialize_interface_runtime()` calls `configure_logging()` (the default setup path), `_configured` becomes `True`. This means the flag no longer exclusively tracks "the user explicitly called `configure_logging()`" — it conflates user-initiated configuration with runtime-initiated configuration.
In practice this doesn't cause a functional bug because the `_interface_runtime_initialized` guard prevents `_initialize_interface_runtime()` from re-evaluating the `_configured` check after the first run. However, if the flag is ever read in a future context expecting to know whether the *user* configured logging (rather than just whether *any* call to `configure_logging()` occurred), the semantics will be misleading.
Consider documenting this clearly, or renaming the flag to `_logging_setup_complete` to reflect its actual meaning: logging was configured (by anyone), so skip default setup.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
||
|
|
||
| def quiet_noisy_logger(name: str) -> None: | ||
| logger = logging.getLogger(name) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,14 @@ | |
| quiet_noisy_logger, | ||
| ) | ||
|
|
||
| import data_designer.logging as _logging_mod | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def reset_configured_flag(): | ||
| original = _logging_mod._configured | ||
| yield | ||
| _logging_mod._configured = original | ||
|
Comment on lines
+22
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The fixture captures the current value of If the module is imported in a process where Adding an explicit reset to @pytest.fixture(autouse=True)
def reset_configured_flag():
original = _logging_mod._configured
_logging_mod._configured = False # ensure clean slate for each test
yield
_logging_mod._configured = originalPrompt To Fix With AIThis is a comment left during a code review.
Path: packages/data-designer-config/tests/test_logging.py
Line: 22-26
Comment:
**`reset_configured_flag` fixture restores but does not reset to a known baseline**
The fixture captures the *current* value of `_configured` at fixture setup and restores it on teardown. This is a clean teardown pattern, but it does not guarantee `_configured = False` at the *start* of each test.
If the module is imported in a process where `configure_logging()` was already called before the test session starts (e.g., by a conftest or another test module), `original` will be `True` and any test that implicitly relies on `_configured` starting as `False` will see `True` throughout.
Adding an explicit reset to `False` at the start of the fixture (before `yield`) would make the test isolation unconditional:
```python
@pytest.fixture(autouse=True)
def reset_configured_flag():
original = _logging_mod._configured
_logging_mod._configured = False # ensure clean slate for each test
yield
_logging_mod._configured = original
```
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
|
|
||
| @pytest.fixture | ||
| def stub_default_logging_config(): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing blank line before top-level function (PEP 8)
PEP 8 requires two blank lines between top-level definitions. Currently only one blank line separates
_configured = Falsefromdef configure_logging(...).Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!