dbt-labs / dbt-core

dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.
https://getdbt.com
Apache License 2.0
9.37k stars 1.56k forks source link

[Bug] Running `dbt build --resource-type saved_query` on 1.7 throws an uncaught exception #10225

Open Jstein77 opened 2 months ago

Jstein77 commented 2 months ago

Is this a new bug in dbt-core?

Current Behavior

When on dbt 1.7 running dbt build --resource-type saved_query returns the following error when the env var DBT_INCLUDE_SAVED_QUERY is not set.

           ^^^^^^^^^^^^^^^^^^^^^
  File "/venv/dbt-1.7.0-latest/lib/python3.11/site-packages/dbt/cli/main.py", line 220, in build
    results = task.run()
              ^^^^^^^^^^
  File "/venv/dbt-1.7.0-latest/lib/python3.11/site-packages/dbt/task/runnable.py", line 502, in run
    result = self.execute_with_hooks(selected_uids)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/dbt-1.7.0-latest/lib/python3.11/site-packages/dbt/task/runnable.py", line 463, in execute_with_hooks
    res = self.execute_nodes()
          ^^^^^^^^^^^^^^^^^^^^
  File "/venv/dbt-1.7.0-latest/lib/python3.11/site-packages/dbt/task/runnable.py", line 387, in execute_nodes
    self.run_queue(pool)
  File "/venv/dbt-1.7.0-latest/lib/python3.11/site-packages/dbt/task/runnable.py", line 302, in run_queue
    runner = self.get_runner(node)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/venv/dbt-1.7.0-latest/lib/python3.11/site-packages/dbt/task/runnable.py", line 189, in get_runner
    return cls(self.config, adapter, node, run_count, num_nodes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not callable

Instead of falling over, we should return an user friendly error with instructions on how to resolve the issue.

Expected Behavior

We should show a more user friendly error for example:

Error: Could not run saved queries. The environment variable {env_var} is set to FALSE. Please set this the env var {env_var} to true in your dbt_project.yml, or include the --include-saved-query flag.

Steps To Reproduce

In 1.7 run dbt build --resource-type saved_query.

Relevant log output

No response

Environment

- OS: Mac
- Python: 3.9.16
- dbt: 1.7

Which database adapter are you using with dbt?

No response

Additional Context

No response

dbeatty10 commented 1 month ago

Thanks for reporting this @Jstein77 🤩 See "reprex" below for a reproducible example.

Question for you: when using dbt v1.7, does it actually need to raise a friendly like the following?

Error: Could not run saved queries. The environment variable {env_var} is set to FALSE. Please set this the env var {env_var} to true in your dbt_project.yml, or include the --include-saved-query flag.

Or can it just behave the same way as v1.8 and show it as a NO-OP?

Screenshot from v1.8

dbt build --resource-type saved_query --no-include-saved-query
image
### Reprex `models/metricflow_time_spine.sql` ```sql -- https://docs.getdbt.com/docs/build/metricflow-time-spine {{ config(materialized='table') }} with days as ( {{ dbt.date_spine( 'day', "to_date('2000-01-01', 'YYYY-MM-DD')", "to_date('2000-01-05', 'YYYY-MM-DD')" ) }} ), final as ( select cast(date_day as date) as date_day from days ) select * from final ``` `models/_properties.yml` ```yaml metrics: - name: my_metric label: my_metric type: derived type_params: expr: revenue - cost saved_queries: - name: my_saved_query query_params: metrics: - my_metric ``` This works fine when using dbt-core v1.7: ```shell dbt build --resource-type saved_query --include-saved-query ``` But either of these throws an error with a Python stacktrace: ```shell dbt build --resource-type saved_query --no-include-saved-query dbt build --resource-type saved_query ```