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

improve strict undefined #1559

Closed
wants to merge 4 commits into from

Conversation

beckjake
Copy link
Contributor

@beckjake beckjake commented Jun 20, 2019

Fixes #1389

  • During parsing, leave undefined values as non-strict
  • Create a warning cache to avoid duplicate warnings when macros contain an undefined value
  • When compiling hooks, add empty results and schemas to their context.
  • Added some tests to expose this behavior

@beckjake beckjake marked this pull request as ready for review June 20, 2019 16:15
@cmcarthur
Copy link
Member

@beckjake how does that global flag interact across threads? if we are running an RPC server where one thread is in "parse mode" and the other is in "compile mode", what happens?

(same question for WARNING_CACHE)

@beckjake
Copy link
Contributor Author

The RPC server runs dbt in processes, not threads, so globals aren't shared! (technically it's a thread that starts a process, but that's not important)

@cmcarthur
Copy link
Member

The RPC server runs dbt in processes, not threads, so globals aren't shared! (technically it's a thread that starts a process, but that's not important)

Yep, ok, makes sense. But it's also true to say that this adds to the list of things that we would have to change if we wanted to switch from processes to threads in the future, right?

(I don't know that we'd want to do that, just curious)

@beckjake
Copy link
Contributor Author

Yeah. I think at this point threads are pretty infeasible, honestly - just from a control standpoint, you can't kill a thread (yes, there is pthread_kill, never ever use it).

I also realized that when parsing this branch does not set PARSE_MODE=True when it's parsing RPC-provided macros - I'll add that.

@drewbanin
Copy link
Contributor

I think something funky happens when recording the name of the macro where the warning is generated:

-- models/my_model.sql

select 1 as id

{{ macro_1() }}
{{ macro_2() }}
-- macros/my_macro.sql

{% macro macro_1() %}

    {{ kwargs['abc'] }}

{% endmacro %}

{% macro macro_2() %}

    {{ kwargs['def'] }}

{% endmacro %}

This generates the following warnings on dbt run

Compilation warning in macro macro_1 (macros/my_macro.sql):
        'abc' is undefined
Compilation warning in macro macro_1 (macros/my_macro.sql):
        'def' is undefined

I'd expect the second warning to say macro_2, not macro_1

Jacob Beck added 4 commits June 20, 2019 13:39
add tests
remove some weird and wrong test logging
Cache warning messages and make sure we only log them once
I also realized we don't need to clear the warning cache on-fork on windows because it starts empty
@beckjake beckjake force-pushed the fix/improve-strict-undefined branch from 520b647 to d69dace Compare June 20, 2019 18:00
@beckjake
Copy link
Contributor Author

Let's just revert this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dbt should use jinja's StrictUndefined setting
3 participants