diff --git a/core/dbt/events/adapter_endpoint.py b/core/dbt/events/adapter_endpoint.py index 8c9f80b8655..6979256d377 100644 --- a/core/dbt/events/adapter_endpoint.py +++ b/core/dbt/events/adapter_endpoint.py @@ -13,7 +13,7 @@ class AdapterLogger: name: str def debug(self, msg, *args, exc_info=None, extra=None, stack_info=False): - event = AdapterEventDebug(name=self.name, base_msg=str(msg), args=args) + event = AdapterEventDebug(name=self.name, base_msg=msg, args=args) event.exc_info = exc_info event.extra = extra @@ -22,7 +22,7 @@ def debug(self, msg, *args, exc_info=None, extra=None, stack_info=False): fire_event(event) def info(self, msg, *args, exc_info=None, extra=None, stack_info=False): - event = AdapterEventInfo(name=self.name, base_msg=str(msg), args=args) + event = AdapterEventInfo(name=self.name, base_msg=msg, args=args) event.exc_info = exc_info event.extra = extra @@ -31,7 +31,7 @@ def info(self, msg, *args, exc_info=None, extra=None, stack_info=False): fire_event(event) def warning(self, msg, *args, exc_info=None, extra=None, stack_info=False): - event = AdapterEventWarning(name=self.name, base_msg=str(msg), args=args) + event = AdapterEventWarning(name=self.name, base_msg=msg, args=args) event.exc_info = exc_info event.extra = extra @@ -40,7 +40,7 @@ def warning(self, msg, *args, exc_info=None, extra=None, stack_info=False): fire_event(event) def error(self, msg, *args, exc_info=None, extra=None, stack_info=False): - event = AdapterEventError(name=self.name, base_msg=str(msg), args=args) + event = AdapterEventError(name=self.name, base_msg=msg, args=args) event.exc_info = exc_info event.extra = extra @@ -50,7 +50,7 @@ def error(self, msg, *args, exc_info=None, extra=None, stack_info=False): # The default exc_info=True is what makes this method different def exception(self, msg, *args, exc_info=True, extra=None, stack_info=False): - event = AdapterEventError(name=self.name, base_msg=str(msg), args=args) + event = AdapterEventError(name=self.name, base_msg=msg, args=args) event.exc_info = exc_info event.extra = extra @@ -59,7 +59,7 @@ def exception(self, msg, *args, exc_info=True, extra=None, stack_info=False): fire_event(event) def critical(self, msg, *args, exc_info=False, extra=None, stack_info=False): - event = AdapterEventError(name=self.name, base_msg=str(msg), args=args) + event = AdapterEventError(name=self.name, base_msg=msg, args=args) event.exc_info = exc_info event.extra = extra diff --git a/core/dbt/events/base_types.py b/core/dbt/events/base_types.py index ce33b4955c4..c3c427a9733 100644 --- a/core/dbt/events/base_types.py +++ b/core/dbt/events/base_types.py @@ -104,6 +104,13 @@ def level_tag(self) -> str: return "error" +@dataclass # type: ignore[misc] +class MessageStringifier: + def __post_init__(self): + if not isinstance(self.msg, str): + self.msg = str(self.msg) + + # prevents an event from going to the file # This should rarely be used in core code. It is currently # only used in integration tests and for the 'clean' command. diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index 9479074b6e1..66c316024b3 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -12,6 +12,7 @@ ShowException, NodeInfo, Cache, + MessageStringifier, ) from dbt.events.format import format_fancy_output_line, pluralize from dbt.events.serialization import EventSerialization @@ -56,6 +57,9 @@ class AdapterEventBase(EventSerialization, Event): base_msg: str args: Tuple[Any, ...] + def __post_init__(self): + self.base_msg = str(self.base_msg) + # instead of having this inherit from one of the level classes def level_tag(self) -> str: raise Exception("level_tag should never be called on AdapterEventBase") @@ -443,7 +447,7 @@ def message(self) -> str: @dataclass -class MacroEventInfo(InfoLevel): +class MacroEventInfo(InfoLevel, MessageStringifier): msg: str code: str = "M011" @@ -452,7 +456,7 @@ def message(self) -> str: @dataclass -class MacroEventDebug(DebugLevel): +class MacroEventDebug(DebugLevel, MessageStringifier): msg: str code: str = "M012" @@ -1204,7 +1208,7 @@ def message(self) -> str: @dataclass -class InvalidDisabledSourceInTestNode(WarnLevel): +class InvalidDisabledSourceInTestNode(WarnLevel, MessageStringifier): msg: str code: str = "I050" @@ -1213,7 +1217,7 @@ def message(self) -> str: @dataclass -class InvalidRefInTestNode(DebugLevel): +class InvalidRefInTestNode(DebugLevel, MessageStringifier): msg: str code: str = "I051" @@ -1641,7 +1645,7 @@ def message(self) -> str: @dataclass -class RunResultWarningMessage(WarnLevel): +class RunResultWarningMessage(WarnLevel, MessageStringifier): msg: str code: str = "Z049" @@ -1672,7 +1676,7 @@ def message(self) -> str: @dataclass -class RunResultError(ErrorLevel): +class RunResultError(ErrorLevel, MessageStringifier): msg: str code: str = "Z024" @@ -1719,7 +1723,7 @@ def message(self) -> str: @dataclass -class FirstRunResultError(ErrorLevel): +class FirstRunResultError(ErrorLevel, MessageStringifier): msg: str code: str = "Z028" @@ -1728,7 +1732,7 @@ def message(self) -> str: @dataclass -class AfterFirstRunResultError(ErrorLevel): +class AfterFirstRunResultError(ErrorLevel, MessageStringifier): msg: str code: str = "Z029" @@ -2310,7 +2314,7 @@ def message(self) -> str: @dataclass -class GetAddendum(InfoLevel): +class GetAddendum(InfoLevel, MessageStringifier): msg: str code: str = "A026" @@ -2447,7 +2451,7 @@ def message(self) -> str: @dataclass -class GeneralWarningMsg(WarnLevel): +class GeneralWarningMsg(WarnLevel, MessageStringifier): msg: str log_fmt: str code: str = "Z046"