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

[BACKPORT 1.1.latest] Improved event log msg stringification #7338

Merged
merged 4 commits into from
Apr 18, 2023
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-20230331-095428.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions core/dbt/context/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,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=msg))
else:
Expand Down
22 changes: 22 additions & 0 deletions test/unit/test_base_context.py
Original file line number Diff line number Diff line change
@@ -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}"