Skip to content

Commit

Permalink
Move stringification down call stack to any class with a (base_)msg p…
Browse files Browse the repository at this point in the history
…arameter.
  • Loading branch information
VersusFacit committed Oct 16, 2022
1 parent c99290c commit e07829f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
12 changes: 6 additions & 6 deletions core/dbt/events/adapter_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions core/dbt/events/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 14 additions & 10 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ShowException,
NodeInfo,
Cache,
MessageStringifier,
)
from dbt.events.format import format_fancy_output_line, pluralize
from dbt.events.serialization import EventSerialization
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -443,7 +447,7 @@ def message(self) -> str:


@dataclass
class MacroEventInfo(InfoLevel):
class MacroEventInfo(InfoLevel, MessageStringifier):
msg: str
code: str = "M011"

Expand All @@ -452,7 +456,7 @@ def message(self) -> str:


@dataclass
class MacroEventDebug(DebugLevel):
class MacroEventDebug(DebugLevel, MessageStringifier):
msg: str
code: str = "M012"

Expand Down Expand Up @@ -1204,7 +1208,7 @@ def message(self) -> str:


@dataclass
class InvalidDisabledSourceInTestNode(WarnLevel):
class InvalidDisabledSourceInTestNode(WarnLevel, MessageStringifier):
msg: str
code: str = "I050"

Expand All @@ -1213,7 +1217,7 @@ def message(self) -> str:


@dataclass
class InvalidRefInTestNode(DebugLevel):
class InvalidRefInTestNode(DebugLevel, MessageStringifier):
msg: str
code: str = "I051"

Expand Down Expand Up @@ -1641,7 +1645,7 @@ def message(self) -> str:


@dataclass
class RunResultWarningMessage(WarnLevel):
class RunResultWarningMessage(WarnLevel, MessageStringifier):
msg: str
code: str = "Z049"

Expand Down Expand Up @@ -1672,7 +1676,7 @@ def message(self) -> str:


@dataclass
class RunResultError(ErrorLevel):
class RunResultError(ErrorLevel, MessageStringifier):
msg: str
code: str = "Z024"

Expand Down Expand Up @@ -1719,7 +1723,7 @@ def message(self) -> str:


@dataclass
class FirstRunResultError(ErrorLevel):
class FirstRunResultError(ErrorLevel, MessageStringifier):
msg: str
code: str = "Z028"

Expand All @@ -1728,7 +1732,7 @@ def message(self) -> str:


@dataclass
class AfterFirstRunResultError(ErrorLevel):
class AfterFirstRunResultError(ErrorLevel, MessageStringifier):
msg: str
code: str = "Z029"

Expand Down Expand Up @@ -2310,7 +2314,7 @@ def message(self) -> str:


@dataclass
class GetAddendum(InfoLevel):
class GetAddendum(InfoLevel, MessageStringifier):
msg: str
code: str = "A026"

Expand Down Expand Up @@ -2447,7 +2451,7 @@ def message(self) -> str:


@dataclass
class GeneralWarningMsg(WarnLevel):
class GeneralWarningMsg(WarnLevel, MessageStringifier):
msg: str
log_fmt: str
code: str = "Z046"
Expand Down

0 comments on commit e07829f

Please sign in to comment.