fix: add explicit return(none) in get_elementary_relation when relation not found#1020
Conversation
…on not found The v0.24.0 refactoring (PR #1006) added a deferral fallback but removed the unconditional return of adapter.get_relation()'s result. When the adapter returns None and deferral is off, the macro now falls through without calling return(). In dbt's Jinja2, this means the macro returns its rendered template text (whitespace) instead of None. Since a non-empty string is truthy, callers that check `if relation` incorrectly proceed as if the table exists, producing SQL like `from <whitespace>` which causes BigQuery syntax errors. Add an explicit `return(none)` at the end to restore the v0.23.1 contract: when a relation is not found and deferral is not active, the macro returns None. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
👋 @elazarlachkar |
📝 WalkthroughWalkthroughThis PR adds an explicit ChangesDeterministic Relation Lookup
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
The v0.24.0 refactoring in PR #1006 (deferral fallback) broke
get_elementary_relationfor environments where elementary tables don't exist and deferral is not active.Before (v0.23.1):
adapter.get_relation()result was always explicitly returned:{% do return(adapter.get_relation(...)) %} -- None when table missingAfter (v0.24.0): when
adapter.get_relation()returnsNoneand deferral is off, the macro falls through without callingreturn(). In dbt's Jinja2, this returns the rendered template text (whitespace) instead ofNone. A non-empty whitespace string is truthy, so callers checking{% if relation %}proceed as if the table exists — producingfrom <whitespace>in SQL, which causes downstream syntax errors like:Example from Current's environment (does no have a
dbt_modelstable):Fix: add
{% do return(none) %}at the end of the macro to restore the v0.23.1 contract.Related: CORE-930
Link to Devin session: https://app.devin.ai/sessions/1fddd97133934bbd9ab85b4137700ec8
Requested by: @elazarlachkar
Summary by CodeRabbit