Skip to content
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

For undefined variables, explicitly raise a useful error on pickling #2184

Merged
merged 2 commits into from
Mar 6, 2020

Conversation

beckjake
Copy link
Contributor

@beckjake beckjake commented Mar 6, 2020

resolves #2110

Description

Add a more coherent warning on pickling that indicates what the undefined value's name is and (importantly) what file it's in.

I wasn't able to fully remove the defining-Undefined-in-a-closure stuff because without it, we can't give a message indicating where we found the Undefined.

This is the new behavior:

$ cat models/y.sql
select * from {{ ref(x) }}
$ dbt compile
Running with dbt=0.17.0-a1
Encountered an error:
Compilation Error in model y (models/y.sql)
  x is undefined

I would have very much liked to remove the special undefined override, but because of how jinja handles undefined values, it's actually very difficult! You can't make it just raise on undefined, because constants like 1 show up as undefined (I don't understand why or how, but I didn't spend a lot of time on that because what are you going to do, change jinja?). Jinja really only has the capability of erroring out on explicit uses of undefined:

  • missing.x -> can be an error (__getattr__(self) -> error)
  • missing['x'] -> can be an error (__getitem__(self) -> error)
  • missing * x -> can be an error (__mul__(self) -> error)

Cases like foo(missing)where foo doesn't call any of the forbidden magic methods apparently can't be an error without also breaking the use of bare integers.

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt next" section.

@cla-bot cla-bot bot added the cla:yes label Mar 6, 2020
@beckjake beckjake requested a review from drewbanin March 6, 2020 17:15
Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM! Nice one @beckjake

@beckjake beckjake merged commit b77b3a4 into dev/octavius-catto Mar 6, 2020
@beckjake beckjake deleted the fix/ugly-errors-undefined-values branch March 6, 2020 20:26
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.

Running dbt with an invalid table reference returns a cryptic can't pickle ParserMacroCapture objects.
2 participants