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

Re-enable suppression of logging event dictionary parsing errors #203

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20241010-164116.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Suppress logging event dictionary parsing exceptions
time: 2024-10-10T16:41:16.06107-04:00
custom:
Author: gshank
Issue: "202"
7 changes: 3 additions & 4 deletions dbt_common/events/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import threading
from dbt_common.events import types_pb2
import sys
from google.protobuf.json_format import ParseDict, MessageToDict, MessageToJson
from google.protobuf.message import Message
from dbt_common.events.helpers import get_json_string_utcnow
Expand Down Expand Up @@ -65,14 +64,14 @@ def __init__(self, *args, **kwargs) -> None:
kwargs["msg"] = str(kwargs["msg"])
try:
self.pb_msg = ParseDict(kwargs, msg_cls())
except Exception:
except Exception as exc:
# Imports need to be here to avoid circular imports
from dbt_common.events.types import Note
from dbt_common.events.functions import fire_event

error_msg = f"[{class_name}]: Unable to parse dict {kwargs}"
error_msg = f"[{class_name}]: Unable to parse logging event dictionary. {exc}. Dictionary: {kwargs}"
# If we're testing throw an error so that we notice failures
if "pytest" in sys.modules:
if os.getenv("PYTEST_CURRENT_TEST"):
raise Exception(error_msg)
else:
fire_event(Note(msg=error_msg), level=EventLevel.WARN)
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/test_events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import os

import pytest

Expand Down Expand Up @@ -127,11 +128,12 @@ def test_bad_serialization():
that bad serializations are properly handled, the best we can do is test
that the exception handling path is used.
"""

with pytest.raises(Exception) as excinfo:
types.Note(param_event_doesnt_have="This should break")
assert 'has no field named "param_event_doesnt_have" at "Note"' in str(excinfo.value)

assert (
str(excinfo.value)
== "[Note]: Unable to parse dict {'param_event_doesnt_have': 'This should break'}"
)
# With this unset, it shouldn't throw an exception
saved = os.environ["PYTEST_CURRENT_TEST"]
del os.environ["PYTEST_CURRENT_TEST"]
types.Note(param_event_doesnt_have="This should not break")
os.environ["PYTEST_CURRENT_TEST"] = saved
Loading