dbt-labs / dbt-common

Apache License 2.0
13 stars 15 forks source link

fix: catch jinja typeerrors during render phase #207

Open devmessias opened 1 month ago

devmessias commented 1 month ago

resolves #206

Description

After this, a TypeError in render phase will show the node information

 $ dbt build 
12:26:47  Running with dbt=1.9.0-b2
12:26:47  Registered adapter: duckdb=1.9.0
12:26:47  Encountered an error:
Type Error in model ex2 (models/ex2.sql)
  bad operand type for unary -: 'str'

Checklist

github-actions[bot] commented 1 month ago

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

codecov-commenter commented 1 month ago

Codecov Report

Attention: Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 68.42%. Comparing base (1bad6b7) to head (74b437e).

Files with missing lines Patch % Lines
dbt_common/clients/jinja.py 28.57% 5 Missing :warning:
dbt_common/exceptions/base.py 80.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #207 +/- ## ========================================== - Coverage 68.48% 68.42% -0.07% ========================================== Files 52 52 Lines 3389 3401 +12 ========================================== + Hits 2321 2327 +6 - Misses 1068 1074 +6 ``` | [Flag](https://app.codecov.io/gh/dbt-labs/dbt-common/pull/207/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dbt-labs) | Coverage Δ | | |---|---|---| | [unit](https://app.codecov.io/gh/dbt-labs/dbt-common/pull/207/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dbt-labs) | `68.42% <50.00%> (-0.07%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dbt-labs#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

gshank commented 1 month ago

Can you add a unit test? It's not always possible, but its preferable. Also you need to run pre-commit run --all-files to get the code checks to pass.

devmessias commented 1 month ago

Yes, I can! I was just waiting for approval before spending time coding without knowing if the dbt-core team wanted that.

devmessias commented 1 month ago

Done @gshank

But it seems there are other issues not related with this PR

hatch run lint:all                     (base) 
cmd [1] | - python -m black .
All done! ✨ 🍰 ✨
119 files left unchanged.
cmd [2] | - python -m flake8 .
cmd [3] | - python -m mypy .
tests/unit/test_behavior_flags.py:11: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:12: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:24: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:25: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:30: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:35: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:36: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:41: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:66: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:83: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:84: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:98: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:99: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:157: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:173: error: Missing keys ("source", "description", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:179: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
tests/unit/test_behavior_flags.py:180: error: Missing keys ("source", "docs_url") for TypedDict "BehaviorFlag"  [typeddict-item]
devmessias commented 1 week ago

Hey @peterallenwebb , Would you mind taking a look at this PR?