-
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
Var does not exist exception not being caught #3320
Comments
Hey @jpmmcneill, nice catch, and thanks for opening this issue! I'm all for improving this error message, since Jinja errors like Here's where that exception should be raised: Even though the code in your reproduction case definitely goes down the If instead I move the def __call__(self, var_name, default=_VAR_NOTSET):
if self.has_var(var_name):
return self.get_rendered_var(var_name)
elif default is not self._VAR_NOTSET:
return default
else:
dct = {k: self._merged[k] for k in self._merged}
pretty_vars = json.dumps(dct, sort_keys=True, indent=4)
msg = self.UndefinedVarError.format(
var_name, self.node_name, pretty_vars
)
raise_compiler_error(msg, self._node) I manage to get:
I'm not enough of a python whiz to know why it works when stepping through this logic directly, and it doesn't work when calling a function with equivalent logic. I tried removing just the In any case, I'd definitely welcome a fix for this! :) |
Thanks @jtcohen6 for all the detail! Very much appreciate the pointers 😃 Is there a document that recommends a good way of doing local dev on dbt to test this kind of thing? In my company we have a dockerised CLI dbt so it'd be v awkward to switch dbt to a local version. Would it be worth it for me to set up a jaffle shop that runs off some local DBT version? |
@jpmmcneill Yes! Check out the contributing guide. I'd recommend cloning and installing dbt from source in a virtualenv, though it's also possible to run it from docker. |
🙏 thank you! I'll update here if I have a PR ready to go |
Hey @jtcohen6, I think I've narrowed down the behaviour It's a bit of a weird one - basically when that I'm not sure of the order of operations i'm guessing that it's simply that this is during the compile stage of DBT and is desired behaviour. However, that class actually has a Getting rid of this seems to get everything working for me (ie. get more verbose errors showing up - I have tested this in jaffle_shop). I have no context as to why this odd return None function was added here so there might be an some conditional logic to make sure that the original case isn't being blown out of the water here. |
Thanks for your work here @jpmmcneill! The failing unit test on that PR is indeed very informative, since it points us here: It actually looks like we made an opinionated choice about this a few years ago: #1429 I mostly agree with the rationale there, with the big caveat that returning So I see two potential approaches:
What do you think? dbt is a different beast today than it was two years ago. Does it make sense for dbt to raise more aggressive errors about missing variables, wherever and whenever it may find them? |
Hey @jtcohen6 sorry for slow response on this one. I'm not going quiet deliberately, i'll try to follow up with some context of how I'm seeing users getting this issue (hint - i'm developing packages) |
This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue, or it will be closed in 7 days. |
Describe the bug
Var does not exist exception not being caught when var being directly referenced in a loop
Steps To Reproduce
For a given example model
Example 1
will raise an exception:
Required var 'var_that_doesnt_exist' not found in config:
,followed by a list of all the vars supplied to that model.
Example 2
will raise an exception:
'NoneType' object is not iterable
. This is typically found in YAML config issues and such can be confusing in many cases as it's not a typical var style exception.Expected behavior
Examples 1 and 2 to raise the same error (
Required var 'var_that_doesnt_exist' not found in config:
etc). Example 2 is currently failing during thedbt compile
.I'm happy to fix this up if someone points me in the right direction!
System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using: Mac
The output of
python --version
: Python 3.7.4The text was updated successfully, but these errors were encountered: