# The missing guide to debug() in dbt

**URL:** https://discourse.getdbt.com/t/the-missing-guide-to-debug-in-dbt/7557
**Category:** In-Depth Discussions
**Tags:** devblog
**Created:** [March 29, 2023, 4:20pm UTC](https://discourse.getdbt.com/t/the-missing-guide-to-debug-in-dbt/7557 "2023-03-29T16:20:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)
#### Post date: [March 29, 2023, 4:20pm UTC](https://discourse.getdbt.com/t/the-missing-guide-to-debug-in-dbt/7557/1 "2023-03-29T16:20:10Z")

</div>

This is a companion discussion topic for the original entry at [The missing guide to debug() in dbt | dbt Developer Blog](https://docs.getdbt.com/blog/guide-to-jinja-debug)

---

<div class="post-metadata">

### Author: ![joellabes](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/joellabes/32/3980_2.png) [@joellabes](https://discourse.getdbt.com/u/joellabes)
#### Post date: [March 29, 2023, 10:58pm UTC](https://discourse.getdbt.com/t/the-missing-guide-to-debug-in-dbt/7557/2 "2023-03-29T22:58:17Z")

</div>

Thanks @bper! I’ve never used `debug()` but am now keen to give it a try myself. There’s definitely times I would have found it useful in the past 👀

One question: you said in the post

> if […] while in debug mode you press `c`, the debugger will stop at each of your breakpoints

Does this mean that a `{{ debug() }}` call very early on in your file would be almost impossible to trigger? I can understand how enough time would pass to trigger the breakpoint if you’re trying to capture something that happens in an `on-run-end` hook, but what about if you were debugging something in `on-run-start`?

Or are you also allowed to press `c` while dbt is doing the initial parse work etc, which means that you don’t need the quickest draw in the west to make it work?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)
#### Post date: [March 29, 2023, 10:58pm UTC](https://discourse.getdbt.com/t/the-missing-guide-to-debug-in-dbt/7557/3 "2023-03-29T22:58:17Z")

</div>



---

<div class="post-metadata">

### Author: ![bper](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@bper](https://discourse.getdbt.com/u/bper)
#### Post date: [March 30, 2023, 7:34am UTC](https://discourse.getdbt.com/t/the-missing-guide-to-debug-in-dbt/7557/4 "2023-03-30T07:34:18Z")

</div>

Great question @joellabes

`c` stands for `continue`, e.g. continue from the current breakpoint until the next one (or until the end of the program).

So you don’t need to type `c` to trigger the first breakpoint, it will happen automatically (and you wont’t need the quickest draw in the west). If you have multiple breakpoints though, after you enter the first one you might want to type `c` to execute all the code until the next one.

---

<div class="post-metadata">

### Author: ![roberbonox](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@roberbonox](https://discourse.getdbt.com/u/roberbonox)
#### Post date: [August 21, 2023, 5:02am UTC](https://discourse.getdbt.com/t/the-missing-guide-to-debug-in-dbt/7557/5 "2023-08-21T05:02:38Z")

</div>

Hi how are u, i’m currently working in a use case in which i want to use the VALIDATE function in snowflake to valide COPY INTO statements, i’m creating an incremental model to load into a table the result of this function but i need a query id from the last copy made in snowflake, to obtain that i created the next macro and i put all the {{ debug() }} macros inside tu reach the point in which this macro doesn’t return the expected result:

> {% macro log\_error\_but\_validate() %}  
> {{ debug() }}  
> {% set query\_id\_validacion %}  
> SELECT QUERY\_ID FROM TABLE(INFORMATION\_SCHEMA.QUERY\_HISTORY\_BY\_WAREHOUSE(WAREHOUSE\_NAME =\> ‘WH\_LOADER’)) WHERE DATABASE\_NAME LIKE ‘XXX’ AND SCHEMA\_NAME LIKE ‘YYY’ AND QUERY\_TYPE LIKE ‘COPY’ ORDER BY START\_TIME DESC LIMIT 1  
> {% endset %}  
> {{ debug() }}  
> {% set results = run\_query(query\_id\_validacion) %}  
> {{ debug() }}  
> {% if execute %}  
> {{ debug() }}  
> {% for row in results.rows %}  
> {{ debug() }}  
> {% set retval = row[1] %}  
> {{ debug() }}  
> {{ retval }}  
> {{ debug() }}  
> {% endfor %}
> 
> ```
> {% endif %}
> 
> ```
> 
> {% endmacro %}

The problem seems to be in the query itself: {% set query\_id\_validacion %}

> ```
> SELECT QUERY_ID FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY_BY_WAREHOUSE(WAREHOUSE_NAME => 'WH_LOADER')) WHERE DATABASE_NAME LIKE 'XXX' AND SCHEMA_NAME LIKE 'YYY' AND QUERY_TYPE LIKE 'COPY' ORDER BY START_TIME DESC LIMIT 1
> {% endset %}
> 
> ```

When i debug in the next point i obtain the result and seems to be ok:

```auto
ipdb> pp l_1_query_id_validacion
('\n'
 ' SELECT QUERY_ID FROM '
 'TABLE(INFORMATION_SCHEMA.QUERY_HISTORY_BY_WAREHOUSE(WAREHOUSE_NAME => '
 "'WH_LOADER')) WHERE DATABASE_NAME LIKE 'XXX' AND SCHEMA_NAME LIKE "
 "'YYY' AND QUERY_TYPE LIKE 'COPY' ORDER BY START_TIME DESC LIMIT 1\n"
 ' ')

```

But when i tried to manually change the variable as was explained in this posts i got the following error message,

> ipdb\> l\_1\_query\_id\_validacion = '\n select query\_id from table(information\_schema.query\_history\_by\_warehouse(warehouse\_name =\> ‘WH\_LOADER\_BUT’)) where database\_name like ‘RAW\_DEV’ and schema\_na  
> me like ‘BDOT’ and query\_type like ‘COPY’ order by start\_time desc limit 1 \n ’  
> \*\*\* SyntaxError: invalid syntax. Perhaps you forgot a comma?

I think the problem actually is with the ‘=\>’, any thoughts on how to achieve this? thanks
