Skip to content

Fix misleading warning when evaluating Jinja in dbt_project.yml fails #388

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fornwall
Copy link
Contributor

@fornwall fornwall commented Jul 13, 2025

Fixes #387.

For a dbt_project.yml with the e.g. following model section:

models:
  my_model:
    +hours_to_expiration: "{{ env_var('MY_ENV_VAR') }}"

The behaviour before this PR when the MY_ENV_VAR variable is not defined:

warning: (will error post beta) dbt1060: Ignored unexpected key "my_model". YAML path: my_model.
[..]
warning: dbt1000: Warnings marked (will error post beta) will turn into errors before leaving beta. Please fix them.
suggestion: Try the autofix script: https://github.com/dbt-labs/dbt-autofix

The behaviour after this PR when the MY_ENV_VAR variable is not defined:

error: dbt1013: Failed to parse my_model: Failed to eval the compiled Jinja expression invalid operation: 'env_var': environment variable 'MY_ENV_VAR' not found

See #385 and #386 for two minor polish changes for this error message.

It would be even better to pinpoint +hours_to_expiration in the error message, but that seems to require more invasive changes to the yaml parsing so is left for the future now.

@fornwall fornwall requested a review from a team as a code owner July 13, 2025 02:09
@cla-bot cla-bot bot added the cla:yes label Jul 13, 2025
@fornwall fornwall force-pushed the fix-387-misleading-warning branch from 8d04225 to d4b84b2 Compare July 13, 2025 02:21
@fornwall
Copy link
Contributor Author

fornwall commented Jul 13, 2025

AFAIK we don't need show_warning_soon_to_be_error here, as the real Ignored unexpected key message for unexpected yaml keys is generated here: https://github.com/dbt-labs/dbt-fusion/blob/main/crates/dbt-jinja-utils/src/serde.rs#L279C14-L279C36, and then dispatched with show_warning_soon_to_be_error here: https://github.com/dbt-labs/dbt-fusion/blob/main/crates/dbt-jinja-utils/src/serde.rs#L253-L263

@fornwall
Copy link
Contributor Author

I don't know what the best way to add a test for this. Perhaps it's best to use some high level integration test for parsing projects and assert results, to exercise the interactions between the yaml parser and later processing such as error handling?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Misleading warning when evaluating Jinja in dbt_project.yml fails
1 participant