-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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-792] [Bug] Warnings are being logged as errors during dbt test
#5424
Comments
dbt test
dbt test
quick disclaimer: I am a relatively new product manager at dbt Labs working in Core. I'm fairly confident all of this is correct, but unsure of exactly how to fix (at least without side affects I'm not sure are okay). I am able to verify the issue and (roughly) find the root cause. Normal CLI output for a (debug) cody@dbtpro debug-dbt % dbt test
20:36:05 Running with dbt=1.1.1
20:36:05 Found 5 models, 1 test, 0 snapshots, 2 analyses, 224 macros, 0 operations, 0 seed files, 1 source, 0 exposures, 0 metrics
20:36:05
20:36:05 Concurrency: 8 threads (target='dev')
20:36:05
20:36:05 1 of 1 START test unique_stg_green_taxi_color .................................. [RUN]
20:36:08 1 of 1 WARN 1 unique_stg_green_taxi_color ...................................... [WARN 1 in 2.14s]
20:36:08
20:36:08 Finished running 1 test in 2.62s.
20:36:08
20:36:08 Completed with 1 warning:
20:36:08
20:36:08 Warning in test unique_stg_green_taxi_color (models/staging/models.yml)
20:36:08 Status: warn
20:36:08
20:36:08 compiled SQL at target/compiled/nyc_taxi_demo/models/staging/models.yml/unique_stg_green_taxi_color.sql
20:36:08
20:36:08 Done. PASS=0 WARN=1 ERROR=0 SKIP=0 TOTAL=1 However the json output (with a little re-formatting) shows {
"code": "Z024",
"data": {
"msg": "Got 1 result, configured to warn if != 0"
},
"invocation_id": "928cf171-d56b-422d-9013-499787674eaf",
"level": "error",
"log_version": 2,
"msg": " Got 1 result, configured to warn if != 0",
"pid": 8752,
"thread_name": "MainThread",
"ts": "2022-07-22T20:39:02.561431Z",
"type": "log_line"
} This is coming from this line: https://github.com/dbt-labs/dbt-core/blob/main/core/dbt/task/printer.py#L102 It is easy enough to write some logic to instead fire a warning instead of an error, but doing so from my local testing is affecting the logs in other ways I'm not sure are acceptable. For example: c98d7f2 Before change: {"code": "A001", "data": {"v": "=1.1.1"}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "info", "log_version": 2, "msg": "Running with dbt=1.1.1", "pid": 8861, "thread_name": "MainThread", "ts": "2022-07-22T20:42:05.673627Z", "type": "log_line"}
{"code": "W006", "data": {"stat_line": "5 models, 1 test, 0 snapshots, 2 analyses, 224 macros, 0 operations, 0 seed files, 1 source, 0 exposures, 0 metrics"}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "info", "log_version": 2, "msg": "Found 5 models, 1 test, 0 snapshots, 2 analyses, 224 macros, 0 operations, 0 seed files, 1 source, 0 exposures, 0 metrics", "pid": 8861, "thread_name": "MainThread", "ts": "2022-07-22T20:42:05.708022Z", "type": "log_line"}
{"code": "Q026", "data": {"num_threads": 1, "target_name": "dev"}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "info", "log_version": 2, "msg": "Concurrency: 1 threads (target='dev')", "pid": 8861, "thread_name": "MainThread", "ts": "2022-07-22T20:42:06.234328Z", "type": "log_line"}
{"code": "Q033", "data": {"description": "test unique_stg_green_taxi_color", "index": 1, "node_info": {"materialized": "test", "node_finished_at": null, "node_name": "unique_stg_green_taxi_color", "node_path": "unique_stg_green_taxi_color.sql", "node_started_at": "2022-07-22T20:42:06.237576", "node_status": "started", "resource_type": "test", "unique_id": "test.nyc_taxi_demo.unique_stg_green_taxi_color.b72aa30692"}, "total": 1}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "info", "log_version": 2, "msg": "1 of 1 START test unique_stg_green_taxi_color .................................. [RUN]", "pid": 8861, "thread_name": "Thread-1", "ts": "2022-07-22T20:42:06.237914Z", "type": "log_line"}
{"code": "Q010", "data": {"execution_time": 0, "failures": 1, "index": 1, "name": "unique_stg_green_taxi_color", "node_info": {"materialized": "test", "node_finished_at": null, "node_name": "unique_stg_green_taxi_color", "node_path": "unique_stg_green_taxi_color.sql", "node_started_at": null, "node_status": "executing", "resource_type": "test", "unique_id": "test.nyc_taxi_demo.unique_stg_green_taxi_color.b72aa30692"}, "num_models": 1}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "warn", "log_version": 2, "msg": "1 of 1 WARN 1 unique_stg_green_taxi_color ...................................... [\u001b[33mWARN 1\u001b[0m in 0.47s]", "pid": 8861, "thread_name": "Thread-1", "ts": "2022-07-22T20:42:06.706175Z", "type": "log_line"}
{"code": "E040", "data": {"execution": " in 1.00s", "stat_line": "1 test"}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "info", "log_version": 2, "msg": "Finished running 1 test in 1.00s.", "pid": 8861, "thread_name": "MainThread", "ts": "2022-07-22T20:42:06.708953Z", "type": "log_line"}
{"code": "Z030", "data": {"keyboard_interrupt": false, "num_errors": 0, "num_warnings": 1}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "info", "log_version": 2, "msg": "\u001b[33mCompleted with 1 warning:\u001b[0m", "pid": 8861, "thread_name": "MainThread", "ts": "2022-07-22T20:42:06.717999Z", "type": "log_line"}
{"code": "Z021", "data": {"node_name": "unique_stg_green_taxi_color", "path": "models/staging/models.yml", "resource_type": "test"}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "warn", "log_version": 2, "msg": "\u001b[33mWarning in test unique_stg_green_taxi_color (models/staging/models.yml)\u001b[0m", "pid": 8861, "thread_name": "MainThread", "ts": "2022-07-22T20:42:06.718432Z", "type": "log_line"}
{"code": "Z024", "data": {"msg": "Got 1 result, configured to warn if != 0"}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "error", "log_version": 2, "msg": " Got 1 result, configured to warn if != 0", "pid": 8861, "thread_name": "MainThread", "ts": "2022-07-22T20:42:06.718787Z", "type": "log_line"}
{"code": "Z026", "data": {"path": "target/compiled/nyc_taxi_demo/models/staging/models.yml/unique_stg_green_taxi_color.sql"}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "info", "log_version": 2, "msg": " compiled SQL at target/compiled/nyc_taxi_demo/models/staging/models.yml/unique_stg_green_taxi_color.sql", "pid": 8861, "thread_name": "MainThread", "ts": "2022-07-22T20:42:06.719120Z", "type": "log_line"}
{"code": "Z023", "data": {"stats": {"error": 0, "pass": 0, "skip": 0, "total": 1, "warn": 1}}, "invocation_id": "b741ef3d-13e6-427e-ac8f-33d7dc2d6ed9", "level": "info", "log_version": 2, "msg": "Done. PASS=0 WARN=1 ERROR=0 SKIP=0 TOTAL=1", "pid": 8861, "thread_name": "MainThread", "ts": "2022-07-22T20:42:06.719460Z", "type": "log_line"} After change: {"code": "A001", "data": {"v": "=1.1.1"}, "invocation_id": "5dc58a24-6bad-4f66-af08-48459d16aad4", "level": "info", "log_version": 2, "msg": "Running with dbt=1.1.1", "pid": 8952, "thread_name": "MainThread", "ts": "2022-07-22T20:42:52.124460Z", "type": "log_line"}
{"code": "W006", "data": {"stat_line": "5 models, 1 test, 0 snapshots, 2 analyses, 224 macros, 0 operations, 0 seed files, 1 source, 0 exposures, 0 metrics"}, "invocation_id": "5dc58a24-6bad-4f66-af08-48459d16aad4", "level": "info", "log_version": 2, "msg": "Found 5 models, 1 test, 0 snapshots, 2 analyses, 224 macros, 0 operations, 0 seed files, 1 source, 0 exposures, 0 metrics", "pid": 8952, "thread_name": "MainThread", "ts": "2022-07-22T20:42:52.160494Z", "type": "log_line"}
{"code": "Q026", "data": {"num_threads": 1, "target_name": "dev"}, "invocation_id": "5dc58a24-6bad-4f66-af08-48459d16aad4", "level": "info", "log_version": 2, "msg": "Concurrency: 1 threads (target='dev')", "pid": 8952, "thread_name": "MainThread", "ts": "2022-07-22T20:42:52.717238Z", "type": "log_line"}
{"code": "Q033", "data": {"description": "test unique_stg_green_taxi_color", "index": 1, "node_info": {"materialized": "test", "node_finished_at": null, "node_name": "unique_stg_green_taxi_color", "node_path": "unique_stg_green_taxi_color.sql", "node_started_at": "2022-07-22T20:42:52.719700", "node_status": "started", "resource_type": "test", "unique_id": "test.nyc_taxi_demo.unique_stg_green_taxi_color.b72aa30692"}, "total": 1}, "invocation_id": "5dc58a24-6bad-4f66-af08-48459d16aad4", "level": "info", "log_version": 2, "msg": "1 of 1 START test unique_stg_green_taxi_color .................................. [RUN]", "pid": 8952, "thread_name": "Thread-1", "ts": "2022-07-22T20:42:52.719997Z", "type": "log_line"}
{"code": "Q010", "data": {"execution_time": 0, "failures": 1, "index": 1, "name": "unique_stg_green_taxi_color", "node_info": {"materialized": "test", "node_finished_at": null, "node_name": "unique_stg_green_taxi_color", "node_path": "unique_stg_green_taxi_color.sql", "node_started_at": null, "node_status": "executing", "resource_type": "test", "unique_id": "test.nyc_taxi_demo.unique_stg_green_taxi_color.b72aa30692"}, "num_models": 1}, "invocation_id": "5dc58a24-6bad-4f66-af08-48459d16aad4", "level": "warn", "log_version": 2, "msg": "1 of 1 WARN 1 unique_stg_green_taxi_color ...................................... [\u001b[33mWARN 1\u001b[0m in 0.43s]", "pid": 8952, "thread_name": "Thread-1", "ts": "2022-07-22T20:42:53.150600Z", "type": "log_line"}
{"code": "E040", "data": {"execution": " in 0.99s", "stat_line": "1 test"}, "invocation_id": "5dc58a24-6bad-4f66-af08-48459d16aad4", "level": "info", "log_version": 2, "msg": "Finished running 1 test in 0.99s.", "pid": 8952, "thread_name": "MainThread", "ts": "2022-07-22T20:42:53.152556Z", "type": "log_line"}
{"code": "Z030", "data": {"keyboard_interrupt": false, "num_errors": 0, "num_warnings": 1}, "invocation_id": "5dc58a24-6bad-4f66-af08-48459d16aad4", "level": "info", "log_version": 2, "msg": "\u001b[33mCompleted with 1 warning:\u001b[0m", "pid": 8952, "thread_name": "MainThread", "ts": "2022-07-22T20:42:53.159532Z", "type": "log_line"}
{"code": "Z021", "data": {"node_name": "unique_stg_green_taxi_color", "path": "models/staging/models.yml", "resource_type": "test"}, "invocation_id": "5dc58a24-6bad-4f66-af08-48459d16aad4", "level": "warn", "log_version": 2, "msg": "\u001b[33mWarning in test unique_stg_green_taxi_color (models/staging/models.yml)\u001b[0m", "pid": 8952, "thread_name": "MainThread", "ts": "2022-07-22T20:42:53.159837Z", "type": "log_line"}
{"code": "Z002", "data": {"e": "__init__() got an unexpected keyword argument 'msg'"}, "invocation_id": "5dc58a24-6bad-4f66-af08-48459d16aad4", "level": "error", "log_version": 2, "msg": "Encountered an error:\n__init__() got an unexpected keyword argument 'msg'", "pid": 8952, "thread_name": "MainThread", "ts": "2022-07-22T20:42:53.466416Z", "type": "log_line"} I think I'm clearly missing something in the logic, but will post this comment to capture my investigation. |
@lostmygithubaccount Exactly the right spot! A test warning is being fired as The test status and message gets set in the dbt-core/core/dbt/task/test.py Lines 190 to 196 in 1071a46
The message correctly contains the word "warn," so the node should have Then, in the generic task dbt-core/core/dbt/task/printer.py Lines 135 to 136 in 1071a46
dbt-core/core/dbt/task/printer.py Lines 152 to 153 in 1071a46
dbt-core/core/dbt/task/printer.py Lines 83 to 91 in 1071a46
That all works correctly — but then, just below, it also sends it to be fired as a dbt-core/core/dbt/task/printer.py Lines 101 to 104 in 1071a46
When this is a real failure (
IMO the resolution here looks a lot like the one you're recommending:
|
Is there an existing issue for this?
Current Behavior
Warnings are logged as errors during
dbt tests
output when tests have configured thresholds. This is quite an issue for me actually because I want to drive automated alerting on conditions like "are there any error logs" and this totally breaks the ability to do that.Expected Behavior
Warnings should be logged at their appropriate level.
Steps To Reproduce
my_model
will fail (should trigger a warning)dbt --log-format json test
You'll notice the log is written with
"level": "error"
, this is the problem.Relevant log output
No response
Environment
The text was updated successfully, but these errors were encountered: