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

Add environment variables for macro debugging flags (#1628) #1629

Merged
merged 1 commit into from
Jul 26, 2019

Conversation

beckjake
Copy link
Contributor

@beckjake beckjake commented Jul 23, 2019

Fixes #1628 by adding DBT_MACRO_DEBUGGING environment variable support, by default no linecache is set.

While I'm in here adding debugger environment variables, I added two useful tricks I've been using locally so I don't have to keep manually patching them in:

  • when the environment variable is set to write, write the files to disk so the debugging experience is more pleasant. This writes a lot of files and doesn't clean them up! But boy is it helpful sometimes, just to see where you are.
  • when the environment variable is set, a special entry is inserted into the default context: {{ debug() }} will drop you into a debugger at the current line in the compiled macro. This is pretty helpful when you're debugging low-level macro weirdness and don't want to step through a million internal jinja functions just to see where you are.
$ cat models/x.sql
{{ debug() }}
select * from {{ source('src', 'seedtable') }}

With DBT_MACRO_DEBUGGING set:

$ DBT_MACRO_DEBUGGING=true dbt compile
Running with dbt=0.14.0
> /Users/jake/src/fishtown/projects/debug/bfb3707e2a6c4e27ff565365(14)root()

ipdb> l 9,12
      9     l_0_debug = resolve('debug')
     10     l_0_source = resolve('source')
     11     pass
     12     yield '%s\nselect * from %s' % (

With DBT_MACRO_DEBUGGING=write set:

$ DBT_MACRO_DEBUGGING=write dbt compile
Running with dbt=0.14.0
> /var/folders/31/mrzqbbtd3rn4hmgbhrtkfyxm0000gn/T/dbt-macro-compiled-cxvhhgu7.py(14)root()
     13         environment.call(context, (undefined(name='debug') if l_0_debug is missing else l_0_debug)),
---> 14         environment.call(context, (undefined(name='source') if l_0_source is missing else l_0_source), 'src', 'seedtable'),
     15     )

ipdb> l 9,12
      9     l_0_debug = resolve('debug')
     10     l_0_source = resolve('source')
     11     pass
     12     yield '%s\nselect * from %s' % (

The extra context really shines in longer macro/function call chains when you're walking up and down the stack trying to figure out why all your ref() calls started returning None after your minor tweak to the parser or whatever.

@beckjake beckjake requested a review from drewbanin July 26, 2019 15:38
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 is super cool! Love that you can add a debugger breakpoint :)

@beckjake beckjake merged commit 52c9234 into dev/0.14.1 Jul 26, 2019
@beckjake beckjake deleted the feature/compile-tricks-flag branch July 26, 2019 15:44
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.

The linecache debugging information can be inconvenient on some editors
2 participants