# Error message running compare\_relations macro within dbt-audit-helper package

**URL:** <https://discourse.getdbt.com/t/error-message-running-compare-relations-macro-within-dbt-audit-helper-package/13362>\
**Category:** Help\
**Tags:** testing, bigquery, dbt-cloud, macros\
**Created:** [May 15, 2024, 3:04am UTC](https://discourse.getdbt.com/t/error-message-running-compare-relations-macro-within-dbt-audit-helper-package/13362 "2024-05-15T03:04:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgazeyreyn](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@dgazeyreyn](https://discourse.getdbt.com/u/dgazeyreyn)\
**Post date:** [May 15, 2024, 3:04am UTC](https://discourse.getdbt.com/t/error-message-running-compare-relations-macro-within-dbt-audit-helper-package/13362/1 "2024-05-15T03:04:15Z")

</div>

## The problem I’m having

Receiving the following error message while running the compare\_relations macro within the audit-helper package:

“Error while parsing node: inline\_query Macro get\_filtered\_columns\_in\_relation expected a Relation but received the value: None”

## The context of why I’m trying to do this

I’ve refactored a legacy model based on dbt best practices and attempting to compare the legacy model to the refactored model as part of the auditing process. I’m relying on the dbt-audit-helper package to do this and the compare\_relations macro in particular to accomplish.

## What I’ve already tried

I’ve researched other posts and the following post seems to be related to my issue:

> [@adapter.get\_relation compiling strangely](https://discourse.getdbt.com/t/adapter-get-relation-compiling-strangely/7955):
>
> The problem I’m having pre-reqs: We’re on dbt-core 1.3.3, using the latest release of every package we have. The adapter.get\_relation function seems to be compiling strangely. It looks to be compiling the relation of both the file being compiled and the relations specified within the file. This causes issues when attempting to use the audit\_helper package, which is throwing the following error: 16:57:37 Encountered an error: Compilation Error in analysis group\_campaign\_relation\_audit (analy…

If you scroll down, you’ll notice @pempey offers a suggestion: " if I wrapped my jina in and `{% if execute %}` block it resolved my problem."

@jcampion then confirms that resolved here issue: “Wrapping the audit\_helper function in the {% if execute %} block solved it. Thanks so much.”

However, I’m not sure how to apply this (aka wrap audit\_helper function in the {% if execute %} block) as it relates to my code (below). If someone can provide details/advise on what that looks like, I can give a shot.

## Some example code or error messages

Here is my code that is throwing the error referenced above.

```auto
{# in dbt Develop #}

{% set old_etl_relation=adapter.get_relation(
      database=target.database,
      schema="analytics",
      identifier="type_2_user_signups"
) -%}

{% set dbt_relation=ref('fct_type_2_user_signups') %}

{{ audit_helper.compare_relations(
    a_relation=old_etl_relation,
    b_relation=dbt_relation,
    exclude_columns=["loaded_at"],
    primary_key="visitors_mduid"
) }}

```

Just as an FYI, “analytics” is the name of the schema within BigQuery, “type\_2\_user\_signups” is the name of the legacy model/query in that schema and “fct\_type\_2\_user\_signups” is the name of the refactored model/query in that schema.

---

<div class="post-metadata">

**Author:** ![jcampion](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jcampion/32/3452_2.png) [@jcampion](https://discourse.getdbt.com/u/jcampion)\
**Post date:** [May 15, 2024, 1:28pm UTC](https://discourse.getdbt.com/t/error-message-running-compare-relations-macro-within-dbt-audit-helper-package/13362/2 "2024-05-15T13:28:24Z")

</div>

Hi Dave,  
Try this:

> {# in dbt Develop #}
> 
> {% set old\_etl\_relation=adapter.get\_relation(  
> database=target.database,  
> schema=“analytics”,  
> identifier=“type\_2\_user\_signups”  
> ) -%}
> 
> {% set dbt\_relation=ref(‘fct\_type\_2\_user\_signups’) %}

{% if execute %}

> {{ audit\_helper.compare\_relations(  
> a\_relation=old\_etl\_relation,  
> b\_relation=dbt\_relation,  
> exclude\_columns=[“loaded\_at”],  
> primary\_key=“visitors\_mduid”  
> ) }}

{% endif %}

---

<div class="post-metadata">

**Author:** ![dgazeyreyn](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@dgazeyreyn](https://discourse.getdbt.com/u/dgazeyreyn)\
**Post date:** [May 15, 2024, 3:00pm UTC](https://discourse.getdbt.com/t/error-message-running-compare-relations-macro-within-dbt-audit-helper-package/13362/3 "2024-05-15T15:00:08Z")

</div>

> [@jcampion](#):
>
> > {# in dbt Develop #}
> > 
> > {% set old\_etl\_relation=adapter.get\_relation(  
> > database=target.database,  
> > schema=“analytics”,  
> > identifier=“type\_2\_user\_signups”  
> > ) -%}
> > 
> > {% set dbt\_relation=ref(‘fct\_type\_2\_user\_signups’) %}
> 
> {% if execute %}
> 
> > {{ audit\_helper.compare\_relations(  
> > a\_relation=old\_etl\_relation,  
> > b\_relation=dbt\_relation,  
> > exclude\_columns=[“loaded\_at”],  
> > primary\_key=“visitors\_mduid”  
> > ) }}
> 
> {% endif %}

Thanks a lot for the quick response @jcampion !

I gave that a shot and the good news is I’m not receiving the error message anymore but I’m also not receiving any results. Please find a screenshot attached.

Best,  
Dave

 ![Screenshot 2024-05-15 at 10.57.41 AM](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/2X/f/f144735879a62e4cb78ca3b30ef612bdce2bef2e.png)

---

<div class="post-metadata">

**Author:** ![jcampion](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jcampion/32/3452_2.png) [@jcampion](https://discourse.getdbt.com/u/jcampion)\
**Post date:** [May 15, 2024, 3:14pm UTC](https://discourse.getdbt.com/t/error-message-running-compare-relations-macro-within-dbt-audit-helper-package/13362/4 "2024-05-15T15:14:15Z")

</div>

Hi Dave,  
I don’t know why you have no output at all. Perhaps try compiling and see what SQL is generated.

- Judy

---

<div class="post-metadata">

**Author:** ![dgazeyreyn](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@dgazeyreyn](https://discourse.getdbt.com/u/dgazeyreyn)\
**Post date:** [May 15, 2024, 3:54pm UTC](https://discourse.getdbt.com/t/error-message-running-compare-relations-macro-within-dbt-audit-helper-package/13362/5 "2024-05-15T15:54:35Z")

</div>

> [@jcampion](#):
>
> > {# in dbt Develop #}
> > 
> > {% set old\_etl\_relation=adapter.get\_relation(  
> > database=target.database,  
> > schema=“analytics”,  
> > identifier=“type\_2\_user\_signups”  
> > ) -%}
> > 
> > {% set dbt\_relation=ref(‘fct\_type\_2\_user\_signups’) %}
> 
> {% if execute %}
> 
> > {{ audit\_helper.compare\_relations(  
> > a\_relation=old\_etl\_relation,  
> > b\_relation=dbt\_relation,  
> > exclude\_columns=[“loaded\_at”],  
> > primary\_key=“visitors\_mduid”  
> > ) }}
> 
> {% endif %}

Ok, it appears everything is working as expected!

I initially tried compiling as you recommended and it threw an error message similar to the original referenced above. I then noticed I was attempting to run on my Production schema (“analytics”) instead of my Development schema and questioned if that could be the culprit. After switching, compiling no longer threw an error message and previewing actually worked (screenshot below). I’m not sure if that’s exactly what resolved it but wanted to share in case helpful to someone else.

Really appreciate all your help in working through this Judy.

Best,  
Dave

 ![Screenshot 2024-05-15 at 11.53.16 AM](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/2X/a/aad61ce584bc9381e800da6f19b5bb7e512181c6.png)

---

<div class="post-metadata">

**Author:** ![jcampion](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jcampion/32/3452_2.png) [@jcampion](https://discourse.getdbt.com/u/jcampion)\
**Post date:** [May 15, 2024, 4:06pm UTC](https://discourse.getdbt.com/t/error-message-running-compare-relations-macro-within-dbt-audit-helper-package/13362/6 "2024-05-15T16:06:28Z")

</div>

Hi Dave,  
So glad it worked out, and it looks like you have a 100% match. Congratulations!

- Judy

---

<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:** [May 25, 2024, 12:21am UTC](https://discourse.getdbt.com/t/error-message-running-compare-relations-macro-within-dbt-audit-helper-package/13362/7 "2024-05-25T00:21:08Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
