From 44b3ed5ae9a8a6f371c0d277bef56468a18f5386 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Mon, 24 Jul 2023 13:35:27 -0700 Subject: [PATCH] [CT-2594] Fix serialization of `warn_error_options` on Contexts (#8180) * Add test ensuring `warn_error_options` is dictified in `invocation_args_dict` of contexts * Add dictification specific to `warn_error_options` in `args_to_dict` * Changie doc for serialization changes of warn_error_options --- .changes/unreleased/Fixes-20230720-161513.yaml | 6 ++++++ core/dbt/utils.py | 4 ++++ tests/unit/test_context.py | 3 +++ 3 files changed, 13 insertions(+) create mode 100644 .changes/unreleased/Fixes-20230720-161513.yaml diff --git a/.changes/unreleased/Fixes-20230720-161513.yaml b/.changes/unreleased/Fixes-20230720-161513.yaml new file mode 100644 index 00000000000..9dd9c291cf3 --- /dev/null +++ b/.changes/unreleased/Fixes-20230720-161513.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Ensure `warn_error_options` get serialized in `invocation_args_dict` +time: 2023-07-20T16:15:13.761813-07:00 +custom: + Author: QMalcolm + Issue: "7694" diff --git a/core/dbt/utils.py b/core/dbt/utils.py index fa489b1ede0..72fc4fcfdc6 100644 --- a/core/dbt/utils.py +++ b/core/dbt/utils.py @@ -17,6 +17,7 @@ from contextlib import contextmanager from dbt.events.types import RetryExternalCall, RecordRetryException +from dbt.helper_types import WarnErrorOptions from dbt import flags from enum import Enum from typing_extensions import Protocol @@ -655,6 +656,9 @@ def args_to_dict(args): # this was required for a test case if isinstance(var_args[key], PosixPath) or isinstance(var_args[key], WindowsPath): var_args[key] = str(var_args[key]) + if isinstance(var_args[key], WarnErrorOptions): + var_args[key] = var_args[key].to_dict() + dict_args[key] = var_args[key] return dict_args diff --git a/tests/unit/test_context.py b/tests/unit/test_context.py index ef11280f647..b51e8e76de5 100644 --- a/tests/unit/test_context.py +++ b/tests/unit/test_context.py @@ -424,6 +424,9 @@ def test_invocation_args_to_dict_in_macro_runtime_context( # Comes from unit/utils.py config_from_parts_or_dicts method assert ctx["invocation_args_dict"]["profile_dir"] == "/dev/null" + assert isinstance(ctx["invocation_args_dict"]["warn_error_options"], Dict) + assert ctx["invocation_args_dict"]["warn_error_options"] == {"include": [], "exclude": []} + def test_model_parse_context(config_postgres, manifest_fx, get_adapter, get_include_paths): ctx = providers.generate_parser_model_context(