[logging] include reference to `execute` mode check when introspective queries like `run_query` are skipped
- Dominant language
- Rust
- Stars
- 13.8k
- Forks
- 2.6k
- Avg merge
- 21h 31m
- Merged PRs (30d)
- 56
Description
### Is this your first time submitting a feature request?
- [X] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [X] I have searched the existing issues, and I could not find an existing issue for this feature
- [X] I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion
### Describe the feature
When using functions like `run_query`, the [`if execute`](https://docs.getdbt.com/reference/dbt-jinja-functions/execute) check is necessary to avoid failures during the parse phase. Otherwise,
> Any Jinja that relies on a result being returned from the database will error during the parse phase.
> The error returned by dbt will look as follows:
```
Encountered an error:
Compilation Error in model order_payment_methods (models/order_payment_methods.sql)
'None' has no attribute 'table'
```
Let's provide information about why this happened inline. Something like this:
```
Running dbt...
Encountered an error:
Compilation Error in model order_payment_methods (models/order_payment_methods.sql)
'None' has no attribute 'table'
dbt is currently not running in execute mode. You might need to wrap this code in an `if execute` block https://docs.getdbt.com/reference/dbt-jinja-functions/execute
```
### Describe alternatives you've considered
I don't know if we actually can update the Compilation Error message with guidance because it's too late by then, so alternatively we could also add a warning line inside of run_query and friends so you wind up with something like this:
```
Running dbt...
WARN: run_query was invoked in the model order_payment_methods, but dbt is currently not running in execute mode so accessing the result will fail. Wrap in an `if execute` block https://docs.getdbt.com/reference/dbt-jinja-functions/execute
Encountered an error:
Compilation Error in model order_payment_methods (models/order_payment_methods.sql)
'None' has no attribute 'table'
```
### Who will this benefit?
Pretty much everyone who uses introspection, including:
- users getting started with dbt as [recently as today](https://getdbt.slack.com/archives/CBSQTAPLG/p1732771017848259)
- [me, 4 years ago](https://getdbt.slack.com/archives/C0VLZPLAE/p1611781753072000?thread_ts=1611289944.020500&cid=C0VLZPLAE) (when I had already been using dbt for a year and really should have Known Better)
### Are you interested in contributing this feature?
Maybe, if it turns out to just be "update an error message somewhere" but probably not realistically
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.