dbt-labs / dbt-project-evaluator

This package contains macros and models to find DAG issues automatically
https://dbt-labs.github.io/dbt-project-evaluator/latest/
Apache License 2.0
453 stars 69 forks source link

print_dbt_project_evaluator_issues macro broken on BigQuery #502

Closed tomwphillips closed 1 month ago

tomwphillips commented 1 month ago

Describe the bug

We're running dbt project evaluator on our dbt project (using BigQuery). If you have on-run-end configured in dbt_project.yml to run the macro, as follows, it fails to pretty print the issues with the BigQuery adapter and instead prints a BigQuery error.

on-run-end: "{{ dbt_project_evaluator.print_dbt_project_evaluator_issues() }}"

Steps to reproduce

  1. Set up a dbt project on BigQuery with dbt project evaluator.
  2. Configure the project so at least one rule fails.
  3. Build dbt project evaluator.
  4. Note the on-run-end failure.

Expected results

Pretty printed output, like:

% dbt build -s models/dbt_project_evaluator
14:02:53  Running with dbt=1.9.0-a1
14:02:54  Registered adapter: bigquery=1.8.2
14:03:00  Found [redacted]
14:03:00  
14:03:03  Concurrency: 10 threads (target='dev')
14:03:03  
14:03:03  1 of 2 START sql view model dp_dev.fct_models_without_valid_owner .............. [RUN]
14:03:05  1 of 2 OK created sql view model dp_dev.fct_models_without_valid_owner ......... [CREATE VIEW (0 processed) in 2.45s]
14:03:05  2 of 2 START test dbt_project_evaluator_is_empty_fct_models_without_valid_owner_  [RUN]
14:03:08  2 of 2 FAIL 1 dbt_project_evaluator_is_empty_fct_models_without_valid_owner_ ... [FAIL 1 in 2.76s]
14:03:08  
14:03:08  Running 1 on-run-end hook

### List of issues raised by dbt_project_evaluator ###

-- onb.dbt_project_evaluator.dbt_project_evaluator_is_empty_fct_models_without_valid_owner_ --
| resource_name |
| ------------- |
| my_model      |

14:03:10  1 of 1 START hook: onb.on-run-end.0 ............................................ [RUN]
14:03:10  1 of 1 OK hook: onb.on-run-end.0 ............................................... [OK in 0.00s]
14:03:10  
14:03:10  
14:03:10  Finished running 1 view model, 1 test, 1 project hook in 0 hours 0 minutes and 10.03 seconds (10.03s).
14:03:11  
14:03:11  Completed with 1 error and 0 warnings:
14:03:11  
14:03:11  Failure in test dbt_project_evaluator_is_empty_fct_models_without_valid_owner_ (models/dbt_project_evaluator/_dbt_project_evaluator_rules.yml)
14:03:11    Got 1 result, configured to fail if != 0
14:03:11  
14:03:11    compiled code at target/compiled/onb/models/dbt_project_evaluator/_dbt_project_evaluator_rules.yml/dbt_project_evaluator_is_empty_fct_models_without_valid_owner_.sql
14:03:11  
14:03:11  Done. PASS=1 WARN=0 ERROR=1 SKIP=0 TOTAL=2

(Note in this log output I'm running a custom rule in my models directory.)

Actual results

(data-platform) tom.phillips@ON-LON-MAC107 onb % dbt build -s models/dbt_project_evaluator
15:53:03  Running with dbt=1.9.0-a1
15:53:04  Registered adapter: bigquery=1.8.2
15:53:09  Found [redacted]
15:53:09  
15:53:12  Concurrency: 10 threads (target='dev')
15:53:12  
15:53:12  1 of 2 START sql view model dp_dev.fct_models_without_valid_owner .............. [RUN]
15:53:14  1 of 2 OK created sql view model dp_dev.fct_models_without_valid_owner ......... [CREATE VIEW (0 processed) in 2.21s]
15:53:14  2 of 2 START test dbt_project_evaluator_is_empty_fct_models_without_valid_owner_  [RUN]
15:53:16  2 of 2 FAIL 1 dbt_project_evaluator_is_empty_fct_models_without_valid_owner_ ... [FAIL 1 in 2.09s]
15:53:16  
15:53:16  Running 1 on-run-end hook

### List of issues raised by dbt_project_evaluator ###

-- onb.dbt_project_evaluator.dbt_project_evaluator_is_empty_fct_models_without_valid_owner_ --
15:53:17  BigQuery adapter: https://console.cloud.google.com/bigquery?project=tom-phillips-9dc6&j=bq:EU:90683614-fbef-440a-a10c-cc70e0515fd0&page=queryresults
15:53:17  Database error while running on-run-end
15:53:17  
15:53:17  Finished running 1 view model, 1 test in 0 hours 0 minutes and 7.92 seconds (7.92s).
15:53:19  
15:53:19  Completed with 2 errors and 0 warnings:
15:53:19  
15:53:19  Failure in test dbt_project_evaluator_is_empty_fct_models_without_valid_owner_ (models/dbt_project_evaluator/_dbt_project_evaluator_rules.yml)
15:53:19    Got 1 result, configured to fail if != 0
15:53:19  
15:53:19    compiled code at target/compiled/onb/models/dbt_project_evaluator/_dbt_project_evaluator_rules.yml/dbt_project_evaluator_is_empty_fct_models_without_valid_owner_.sql
15:53:19  
15:53:19    on-run-end failed, error:
 Syntax error: Missing whitespace between literal and alias at [4:37]
15:53:19  
15:53:19  Done. PASS=1 WARN=0 ERROR=2 SKIP=0 TOTAL=3

(Note in this log output I'm running a custom rule in my models directory.)

Screenshots and log output

See above.

System information

packages:
  - package: EqualExperts/dbt_unit_testing
    version: 0.4.12
  - package: dbt-labs/dbt_project_evaluator
    version: 0.11.0
  - package: dbt-labs/dbt_utils
    version: 1.1.1
  - package: calogica/dbt_expectations
    version: 0.10.3
  - package: dbt-labs/codegen
    version: 0.12.1

Which database are you using dbt with?

The output of dbt --version:

1.8.0

Additional context

Are you interested in contributing the fix?

I have a fix and will open a PR.