diff --git a/.changes/unreleased/Fixes-20230331-095428.yaml b/.changes/unreleased/Fixes-20230331-095428.yaml new file mode 100644 index 00000000000..772ce077b7d --- /dev/null +++ b/.changes/unreleased/Fixes-20230331-095428.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Improved failed event serialization handling and associated tests +time: 2023-03-31T09:54:28.701963-07:00 +custom: + Author: QMalcolm + Issue: 7113 7108 6568 diff --git a/core/dbt/context/base.py b/core/dbt/context/base.py index 31035d20aee..1c27f85c77d 100644 --- a/core/dbt/context/base.py +++ b/core/dbt/context/base.py @@ -456,6 +456,10 @@ def log(msg: str, info: bool = False) -> str: {{ log("Running some_macro: " ~ arg1 ~ ", " ~ arg2) }} {% endmacro %}" """ + + if not isinstance(msg, str): + msg = str(msg) + if info: fire_event(MacroEventInfo(msg)) else: diff --git a/test/unit/test_base_context.py b/test/unit/test_base_context.py new file mode 100644 index 00000000000..0dc2d93ddca --- /dev/null +++ b/test/unit/test_base_context.py @@ -0,0 +1,22 @@ +import os + +from dbt.context.base import BaseContext +from jinja2.runtime import Undefined + + +class TestBaseContext: + def test_log_jinja_undefined(self): + # regression test for CT-2259 + try: + os.environ["DBT_ENV_SECRET_LOG_TEST"] = "cats_are_cool" + BaseContext.log(msg=Undefined(), info=True) + except Exception as e: + assert False, f"Logging an jinja2.Undefined object raises an exception: {e}" + + def test_log_with_dbt_env_secret(self): + # regression test for CT-1783 + try: + os.environ["DBT_ENV_SECRET_LOG_TEST"] = "cats_are_cool" + BaseContext.log({"fact1": "I like cats"}, info=True) + except Exception as e: + assert False, f"Logging while a `DBT_ENV_SECRET` was set raised an exception: {e}"