From f96b84d7491a657a74411e081790100d5d45e3fe Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Tue, 28 Mar 2023 16:12:40 -0700 Subject: [PATCH] Add tests for logging jinja2.Undefined objects [CT-2259](https://github.com/dbt-labs/dbt-core/issues/7108) identifies an issue wherein dbt-core 1.0-1.3 raise errors if a jinja2.Undefined object is attempted to be logged. This generally happened in the form of `{{ log(undefined_variable, info=True) }}`. This commit adding this test exists for two reasons 1. Ensure we don't have a regression in this going forward 2. Exist as a commit to be used for backport fixes for dbt-core 1.0-1.3 --- tests/unit/test_base_context.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/unit/test_base_context.py diff --git a/tests/unit/test_base_context.py b/tests/unit/test_base_context.py new file mode 100644 index 00000000000..462323de5d7 --- /dev/null +++ b/tests/unit/test_base_context.py @@ -0,0 +1,12 @@ +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}"