Skip to content
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

FIX-#6237: Log errors only from deepest modin layer #6238

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions modin/logging/logger_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,17 @@ def run_and_log(*args: Tuple, **kwargs: Dict) -> Any:
logger_level(start_line)
try:
result = obj(*args, **kwargs)
except BaseException:
get_logger("modin.logger.errors").exception(stop_line)
except BaseException as e:
# Only log the exception if a deeper layer of the modin stack has not
# already logged it.
if not hasattr(e, "_modin_logged"):
# use stack_info=True so that even if we are a few layers deep in
# modin, we log a stack trace that includes calls to higher layers
# of modin
get_logger("modin.logger.errors").exception(
stop_line, stack_info=True
)
e._modin_logged = True # type: ignore[attr-defined]
raise
finally:
logger_level(stop_line)
Expand Down
26 changes: 25 additions & 1 deletion modin/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,31 @@ def func(do_raise):

assert "func" in get_log_messages()["info"][0]
assert "START" in get_log_messages()["info"][0]
assert "STOP" in get_log_messages("modin.logger.errors")["exception"][0]
assert get_log_messages("modin.logger.errors")["exception"] == [
"STOP::PANDAS-API::func"
]


def test_function_decorator_on_outer_function_6237(monkeypatch, get_log_messages):
@modin.logging.enable_logging
def inner_func():
raise ValueError()

@modin.logging.enable_logging
def outer_func():
inner_func()

with monkeypatch.context() as ctx:
# NOTE: we cannot patch in the fixture as mockin logger.getLogger()
# without monkeypatch.context() breaks pytest
mock_get_logger(ctx)

with pytest.raises(ValueError):
outer_func()

assert get_log_messages("modin.logger.errors")["exception"] == [
"STOP::PANDAS-API::inner_func"
]


def test_class_decorator(monkeypatch, get_log_messages):
Expand Down