From 74637e20e3dddfd7c23e157613361c57ed6e2a03 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Tue, 28 Mar 2023 16:23:14 -0700 Subject: [PATCH] Add tests for checking `DBT_ENV_SECRET_`s don't break logging [CT-1783](https://github.com/dbt-labs/dbt-core/issues/6568) describes a bug in dbt-core 1.0-1.3 wherein when a `DBT_ENV_SECRET_` all `{{ log("logging stuff", info=True) }}` invocations break. This commit adds a test for this for two reasons: 1. Ensure we don't regress to this behavior going forward 2. Act as a base commit for making the backport fixes to dbt-core 1.0-1.3 --- tests/unit/test_base_context.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/unit/test_base_context.py b/tests/unit/test_base_context.py index 462323de5d7..0dc2d93ddca 100644 --- a/tests/unit/test_base_context.py +++ b/tests/unit/test_base_context.py @@ -1,3 +1,5 @@ +import os + from dbt.context.base import BaseContext from jinja2.runtime import Undefined @@ -10,3 +12,11 @@ def test_log_jinja_undefined(self): 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}"