-
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
model test compilation context does not have the var method in scope #2114
Comments
this might be fixed in 0.16 -- @beckjake to check |
Not fixed in 0.16! I'm not sure of the exact cause yet, but there is some very fishy rendering code in @drewbanin - what's the desired behavior here? I kind of think args should be rendered at compile time for both sources and models, in the same context that will render the test itself (otherwise, how would Alternatively, we could fix how tests work, removing the whole idea of the |
Phew, so this one's fun! I think for parity and sanity, we should make the following changes:
That will allow |
This problem is a bit more complicated, and has some design/behavior implications. The reason this works for sources is because dbt renders the field during source parsing (it renders everything except descriptions), and Models don't do that, so this doesn't work. However, on model tests (and source tests!) we have an explicit Because the strings here don't match the regex (and even have curly braces), the test parsing logic passes
and the I still think the thing that's actually wrong here is sources being rendered. Unfortunately, with the way dbt is currently designed, you aren't really supposed to be able to do this - the So the important questions that need to be answered before we proceed are:
|
…rendering Fix source test arg rendering (#2114)
Describe the bug
The
model
test compilation context does not have thevar
method in scope, but this does work correctly in sources.In the following example, I have 2 yml files under
model/staging/user
.source_models.yml
models.yml
If I compile the project with
dbt compile --vars '{"created_at__date": "2020-01-01"}'
I get:var
is not available inmodels.yml
but it's available insource_models.yml
var
should have same scope in both.Steps To Reproduce
source
schema test with a dynamic variable as parameter (in the above example, it'screated_at__date
)compile the project with
--vars {"key": "value"}
Compilation will fail for model test with the error:
'var' is undefined
Expected behavior
It should compile successfully for both
source
andmodel
tests with the given parameterssources and models (and other resource types) should all have access to the var method
Screenshots and log output
If applicable, add screenshots or log output to help explain your problem.
System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using:
macOS Mojave
Version: 10.14.6
The output of
python --version
:Python 3.7.0
Additional context
https://getdbt.slack.com/archives/C2JRRQDTL/p1581354620304600
The text was updated successfully, but these errors were encountered: