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

[CT-2594] [Regression] WarnErrorOptions in invocation_args_dict is not JSON serialisable #7694

Closed
2 tasks done
jared-rimmer opened this issue May 24, 2023 · 5 comments · Fixed by #8180
Closed
2 tasks done
Assignees
Labels
bug Something isn't working regression
Milestone

Comments

@jared-rimmer
Copy link
Contributor

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

  • In dbt 1.5.0 the value for the key warn_error_options in the invocation_arg_dict object is a Python object which looks like "warn_error_options": WarnErrorOptions(include=[], exclude=[]),

Expected Behavior

  • In dbt 1.4.x and earlier the value for the key warn_error_options in the invocation_arg_dict object was a string of a dict object which looks like "warn_error_options\": {\"exclude\":[],\"include\":[]}

Steps To Reproduce

  1. Invoke dbt in 1.4.x with the warn options flag
  2. Do the same in 1.5.0
  3. Observe the difference invocation_arg_dict object

Relevant log output

No response

Environment

- OS: Mac
- Python: 3.8
- dbt: 1.5.0

Which database adapter are you using with dbt?

other (mention it in "Additional Context")

Additional Context

All of them

@jared-rimmer jared-rimmer added bug Something isn't working triage labels May 24, 2023
@github-actions github-actions bot changed the title [Bug] WarnErrorOptions in invocation_args is not JSON serialisable [CT-2594] [Bug] WarnErrorOptions in invocation_args is not JSON serialisable May 24, 2023
@jared-rimmer jared-rimmer changed the title [CT-2594] [Bug] WarnErrorOptions in invocation_args is not JSON serialisable [Bug] WarnErrorOptions in invocation_args_dict is not JSON serialisable May 24, 2023
@jtcohen6 jtcohen6 added this to the v1.5.x milestone May 31, 2023
@jtcohen6
Copy link
Contributor

Thanks @jared-rimmer! This is similar to:

I agree that we should serialize WarnErrorOptions somehow—whether to a real Python dictionary, or a JSON string—before exposing it to the Jinja context. The right spot to do that is probably in args_to_dict:

dbt-core/core/dbt/utils.py

Lines 614 to 656 in 45d6145

# This is used to serialize the args in the run_results and in the logs.
# We do this separately because there are a few fields that don't serialize,
# i.e. PosixPath, WindowsPath, and types. It also includes args from both
# cli args and flags, which is more complete than just the cli args.
# If new args are added that are false by default (particularly in the
# global options) they should be added to the 'default_false_keys' list.
def args_to_dict(args):
var_args = vars(args).copy()
# update the args with the flags, which could also come from environment
# variables or user_config
flag_dict = flags.get_flag_dict()
var_args.update(flag_dict)
dict_args = {}
# remove args keys that clutter up the dictionary
for key in var_args:
if key.lower() in var_args and key == key.upper():
# skip all capped keys being introduced by Flags in dbt.cli.flags
continue
if key in ["cls", "mp_context"]:
continue
if var_args[key] is None:
continue
# TODO: add more default_false_keys
default_false_keys = (
"debug",
"full_refresh",
"fail_fast",
"warn_error",
"single_threaded",
"log_cache_events",
"store_failures",
"use_experimental_parser",
)
default_empty_yaml_dict_keys = ("vars", "warn_error_options")
if key in default_false_keys and var_args[key] is False:
continue
if key in default_empty_yaml_dict_keys and var_args[key] == "{}":
continue
# 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])
dict_args[key] = var_args[key]
return dict_args

Is that something you'd be interested in poking around with? Otherwise, we'll try to include this for a v1.5 patch, but I view it as lower priority relative to other bugs/regressions.

@jtcohen6 jtcohen6 removed the triage label May 31, 2023
@dbeatty10 dbeatty10 changed the title [Bug] WarnErrorOptions in invocation_args_dict is not JSON serialisable [CT-2594] [Regression] WarnErrorOptions in invocation_args_dict is not JSON serialisable Jun 30, 2023
@emmyoop
Copy link
Member

emmyoop commented Jul 17, 2023

May be able to just pass the dbtclass mixin to the warnerroroptions.

@QMalcolm
Copy link
Contributor

Interesting the WarnErrorOptions class already uses the dbtClassMixin 🤔 Specifically WarnErrorOptions inherits IncludeExclude and IncludeExclude inherits dbtClassMixin. So having dbtClassMixin as part of WarnErrorOptions doesn't resolve the issue. It appears to be more of an issue of dictifying nested objects.

@QMalcolm
Copy link
Contributor

@jtcohen6 you said

I agree that we should serialize WarnErrorOptions somehow
Does that mean we're not specifically aiming to give the exact previous output, but just that it is serialized in a more friendly way. I.e. it doesn't need to be "warn_error_options\": {\"exclude\":[],\"include\":[]} but could be "warn_error_options": {"exclude": [], "include": []}

@jared-rimmer how exactly are you going about inspecting the value of invocation_arg_dict? I'm trying to inspect the output of 1.4 to write a test for 1.5 and 1.6, but am finding it difficult to actually ensure the proper initial state is setup 🙃

@jtcohen6
Copy link
Contributor

I.e. it doesn't need to be "warn_error_options\": {\"exclude\":[],\"include\":[]} but could be "warn_error_options": {"exclude": [], "include": []}

I agree with this! Feels much more desirable to expose the information in this way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants