fix(emissions_tracker): raise ValueError for LOGGER output without logging_logger (#1412) - #1416
Open
Prasanthmax wants to merge 1 commit into
Open
Prasanthmax wants to merge 1 commit into
Prasanthmax wants to merge 1 commit into
Conversation
…gging_logger Fixes mlco2#1412. OutputMethod.LOGGER silently appended None to _output_handlers when logging_logger wasn't provided, causing an AttributeError inside a suppress() block later in flush()/stop() — swallowed silently, giving no error and no output. Now raises a clear ValueError at construction time instead. Added test_logger_output_raises_without_logging_logger and test_logger_output_succeeds_with_logging_logger in test_emissions_tracker.py. Updated two existing tests that relied on the old silent-None behavior without ever supplying a real logger: test_save_to_flags_map_to_output_methods_and_warn and test_decorator_flush.
This branch has not been deployed
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.
Closes #1412
Root cause
_init_output_methods()unconditionally appendedself._logging_loggerto
self._output_handlerswhenOutputMethod.LOGGERwas requested.Since
self._logging_loggerdefaults toNoneunless the callerexplicitly passes
logging_logger=LoggerOutput(...), forgetting thatargument silently put
Noneinto the handlers list.The actual failure is worse than a visible crash — it's swallowed
inside a
suppress()block in_persist_data(), sotracker.stop()raises nothing and just silently produces no output.
Fix
Raise a clear
ValueErrorat construction time whenOutputMethod.LOGGERis requested without alogging_logger, insteadof letting
Nonepropagate.Testing
test_logger_output_raises_without_logging_loggerandtest_logger_output_succeeds_with_logging_logger.test_save_to_flags_map_to_output_methods_and_warnandtest_decorator_flush, which relied on the old silent-None behaviorwithout ever supplying a real logger.
Windows-only failures unrelated to this change (RAPL's Linux
/sys/class/powercapassumptions, and one CLI test that shells outto a Unix-only command).
Thanks @sohammishra864-wq for reporting this.