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-2829] [Bug] dbt core doesn't always provide JSON logs in jobs when requested by Cloud #8123

Closed
2 tasks done
sophiad96 opened this issue Jul 17, 2023 · 5 comments
Closed
2 tasks done
Labels
bug Something isn't working stale Issues that have gone stale

Comments

@sophiad96
Copy link

sophiad96 commented Jul 17, 2023

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

An Enterprise customer had a job erroring out due to a missing quotation at the end of a vars statement:

dbt run -m stg_action_defs_from_couchbase --vars ‘{"ctm_odate": "2023-07-11", "ctm_jobname": "JBCPER105221-CMBSJ", "v_flow_nm":"'HEQ_ELIG_AGG'"}

Instead of returning a clear error message to indicate that the missing single quotation at the end is the problem, the job errored out and dbt didn’t display any obvious error logs.

Expected Behavior

The error message found in Datadog should be displayed in the job logs in the UI.

Steps To Reproduce

  1. Create a job and include a run command such as dbt run --vars '{"key": "value"}
  2. Run the job.

Relevant log output

No response

Environment

- OS:
- Python:
- dbt: 1.4

Which database adapter are you using with dbt?

No response

Additional Context

https://dbtlabs.atlassian.net/browse/TRIAGE-549

@sophiad96 sophiad96 added bug Something isn't working triage labels Jul 17, 2023
@github-actions github-actions bot changed the title [Bug] dbt core doesn't always provide JSON logs in jobs when requested by Cloud [CT-2829] [Bug] dbt core doesn't always provide JSON logs in jobs when requested by Cloud Jul 17, 2023
@dbeatty10
Copy link
Contributor

Thank you for reporting this @sophiad96 !

Reprex

It is pretty easy to reproduce this on dbt-core 1.4:

dbt ls --vars ‘{"foo":"'bar'"}

❌ dbt-core 1.4 gives a long stack trace like this:

Traceback (most recent call last):
  File "/my_path/bin/dbt", line 8, in <module>
    sys.exit(cli())
  File "/my_path/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/my_path/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/my_path/lib/python3.9/site-packages/click/core.py", line 1655, in invoke
    sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
  File "/my_path/lib/python3.9/site-packages/click/core.py", line 920, in make_context
    self.parse_args(ctx, args)
  File "/my_path/lib/python3.9/site-packages/click/core.py", line 1378, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/my_path/lib/python3.9/site-packages/click/core.py", line 2360, in handle_parse_result
    value = self.process_value(ctx, value)
  File "/my_path/lib/python3.9/site-packages/click/core.py", line 2316, in process_value
    value = self.type_cast_value(ctx, value)
  File "/my_path/lib/python3.9/site-packages/click/core.py", line 2304, in type_cast_value
    return convert(value)
  File "/my_path/lib/python3.9/site-packages/click/types.py", line 82, in __call__
    return self.convert(value, param, ctx)
  File "/my_path/lib/python3.9/site-packages/dbt/cli/option_types.py", line 19, in convert
    return parse_cli_vars(value)
  File "/my_path/lib/python3.9/site-packages/dbt/config/utils.py", line 11, in parse_cli_vars
    return parse_cli_yaml_string(var_string, "vars")
  File "/my_path/lib/python3.9/site-packages/dbt/config/utils.py", line 21, in parse_cli_yaml_string
    raise OptionNotYamlDictError(var_type, cli_option_name)
dbt.exceptions.OptionNotYamlDictError: Compilation Error
  The --vars argument must be a YAML dictionary, but was of type 'str'

✅ Using dbt-core >=1.5.2, there is no stack trace (which I think means this problem is avoided):

$ dbt ls --vars ‘{"foo":"'bar'"}

22:40:58  The YAML provided in the --vars argument is not valid.
Usage: dbt ls [OPTIONS]
Try 'dbt ls -h' for help.

Error: Invalid value for '--vars': String '‘{foo:'bar'}' is not valid YAML

Next steps

@jtcohen6 #7735 solves this and was already backported to 1.5 in #7878 -- do you want to backport it any further back?

@dbeatty10 dbeatty10 removed the triage label Jul 18, 2023
@jtcohen6
Copy link
Contributor

jtcohen6 commented Jul 19, 2023

Thanks @dbeatty10! Important context here is that these logs are being produced with --log-format json, so I'd guess the operative error here was while trying to serialize the stacktrace to JSON.

I think this will be trickier to backport to 1.4.latest, given the changes we made to the CLI / parameters between v1.4 and v1.5, though not impossible.

@jtcohen6
Copy link
Contributor

Specifically, the issue here is that CLI validation (both argparse for v1.4 + click for v1.5+) returns text to stdout, not JSON. So trying to parse from stdout as JSON would lead to an error.

Copy link
Contributor

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

@github-actions github-actions bot added the stale Issues that have gone stale label Jan 16, 2024
Copy link
Contributor

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2024
dbeatty10 added a commit to dbt-labs/docs.getdbt.com that referenced this issue Jun 14, 2024
…#5660)

[Preview](https://docs-getdbt-com-git-dbeatty10-patch-2-dbt-labs.vercel.app/docs/dbt-versions/core-upgrade/upgrading-to-v1.5#behavior-changes)

## What are you changing in this pull request and why?

In v1.5, we changed the CLI internals from [`argparse` to
`click`](dbt-labs/dbt-core#8123 (comment)).
Since this marked an important change that affected some behavior, it
would be helpful to document that this change took place in v1.5.

## Checklist
- [x] Review the [Content style
guide](https:/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md)
so my content adheres to these guidelines.

---------

Co-authored-by: Matt Shaver <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale Issues that have gone stale
Projects
None yet
Development

No branches or pull requests

3 participants