-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
make undefined strict when not capturing macros (#1389) #1416
Conversation
@beckjake this does look great, but I am just realizing exactly how many macros out in the wild are going to be totally broken once this is merged. I think this is in the category of "bandaids we should rip off sooner rather than later". Let me play around with this on some example projects to determine the extent of the damage. |
We could subclass that class to have it go through a |
Will that approach arrest parsing? I imagine that once the exception is thrown, dbt isn't going to actually parse the rest of the file, right? This is broadly what I had in mind, but I was picturing either 1) tucking this thing behind |
I think we're saying the same thing - I'm just saying you'd do something along these lines (untested, but seems reasonable enough):
Following this pattern: https://github.com/pallets/jinja/blob/a7ba0b637805c53d442e975e3864d3ea38d8743f/jinja2/runtime.py#L801-L803 |
Oh, ok, I think i might misunderstand how this jinja handles undefined values. Sure, let's try something like this! I will ping you to make sure I have the right idea :) |
eefeb95
to
9da0dc8
Compare
Does this close #1389? |
@beckjake this is super close! Are we able to add a I think we can use |
So, I definitely could rewrite the function that generates the message and hope it doesn't change in future jinja versions. That said, how much would you object to just doing:
|
I'm ok with that! Is there a reason we wouldn't go through the existing warn_or_error codepath? The other thing I would love would be to add info about the resource where the undefined variable was found. Is that something that Jinja would make easy for us? I'm picturing:
Just looking at the code though, I'm not sure how we'd be able to snag that from the |
Just that I feel super comfortable letting jinja raise the error and generate a great error message in all sorts of weird edge cases (where does |
If we let jinja do the reporting, I believe we'll catch it here and display something pleasant that includes the file path, right? Ah, I see - only if |
Ah, I meant specifically for the WARNING case, I assumed we'd decorate the error message for an exception... maybe that's not the case.... Let's get this bad boy merged with just a warning log line. Don't worry about the model path -- we're not doing a good job of handling that anywhere at the moment. Presumably if some var is undefined, it will be pretty easy to cmd+f for :) |
Are you sure? I've come up with a reasonably nice solution for it and it's actually not too hard. |
I take it all back! Yeah, give it a shot then! |
Fix a number of tests and some table/view materialization issues
9da0dc8
to
08f75f9
Compare
On warnings it now looks like this:
|
raise errors in strict mode log warnings on warning states Add tests
08f75f9
to
bf9c466
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tiny nitpick on the warning message, but otherwise this is ready to go! It's great to slot in UX niceties like this alongside more fundamental updates/features
Co-Authored-By: beckjake <[email protected]>
Fixes #1389
During the non-macro-capture part of dbt parsing, set the undefined handling to 'strict' - currently we let jinja use its default, which is permissive - many times, overly so.
I expect this will break a good number of macros/models/materializations in end user code.
A fix for a lot of issues is, if
x.y
now raises an error, tryx.get('y', '')
.