# dbt was unable to infer all dependencies for the model on-run-end

**URL:** <https://discourse.getdbt.com/t/dbt-was-unable-to-infer-all-dependencies-for-the-model-on-run-end/15108>\
**Category:** Help\
**Tags:** snowflake, macros, dbt-core\
**Created:** [August 23, 2024, 1:21pm UTC](https://discourse.getdbt.com/t/dbt-was-unable-to-infer-all-dependencies-for-the-model-on-run-end/15108 "2024-08-23T13:21:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gyom](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Gyom](https://discourse.getdbt.com/u/Gyom)\
**Post date:** [August 23, 2024, 1:21pm UTC](https://discourse.getdbt.com/t/dbt-was-unable-to-infer-all-dependencies-for-the-model-on-run-end/15108/1 "2024-08-23T13:21:54Z")

</div>

Hello,

In my dbt project, on -run-end I call a macro to manage some authorization.  
This macro calls a dbt model (called “role\_schema\_matrix”). When running dbt I always get the error message “dbt was unable to infer all dependencies for the model on-run-end”

I get an advice that tells me:  
This typically happens when ref() is placed within a conditional block.  
To fix this, add the following hint to the top of the model “events\_to\_datavault-on-run-end-0”:

– depends\_on: {{ ref(‘role\_schema\_matrix’) }}

so of course I tried to add it at the top of my macro but I still get the same error.  
I also tried to simply add:  
– {{ ref(‘role\_schema\_matrix’) }}  
but the result is still the same, it doesn’t work.

So my dbt\_project.yml looks like that:

![image](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/2X/c/c8c18b57a563e1423ce8d59557897f711d37a19a.png)

My macro looks like that:

```auto
 {% macro grant_select() %}
--{{ ref('role_schema_matrix') }}
   {% for schema in schemas %}
       {{ print ( "schema=" ~schema ) }}
     {# for each schema, we get the roles to be granted #}
     {% set sql_query %}
       select role
       from {{ ref ('role_schema_matrix') }}
        where schema = '{{ schema }}'
     {% endset %}
     {{ print ( "sql_query=" ~sql_query ) }}
 
     {% set results = run_query(sql_query) %}
 
     {% if execute %}
       -- we put the roles in a list ...
       {% set role_list = results.columns[0].values() %}
       {{ print ( "role_list_execute=" ~role_list ) }}
     {% else %}
       {% set role_list = [] %}
       {{ print ( "role_list_else=" ~role_list ) }}
     {% endif %}
   {% endfor %}
 {%- endmacro -%}

```

If I replace the “ref” by a “source”, it works well, but I’d prefer to use the “ref” as it’s a model built in my dbt project.

How can I fix this error?  
Thank you for your help!

---

<div class="post-metadata">

**Author:** ![DataNath](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/datanath/32/4070_2.png) [@DataNath](https://discourse.getdbt.com/u/DataNath)\
**Post date:** [August 23, 2024, 1:56pm UTC](https://discourse.getdbt.com/t/dbt-was-unable-to-infer-all-dependencies-for-the-model-on-run-end/15108/2 "2024-08-23T13:56:03Z")

</div>

Hey @Gyom, I believe the dependency needs to be stated at the very start of the model (as it’s hidden within the macro at the moment) like:

```auto
-- depends_on: {{ ref('role_schema_matrix') }}
 {% macro grant_select() %}
   {% for schema in schemas %}
       {{ print ( "schema=" ~schema ) }}
     {# for each schema, we get the roles to be granted #}
     {% set sql_query %}
       select role
       from {{ ref ('role_schema_matrix') }}
        where schema = '{{ schema }}'
     {% endset %}
     {{ print ( "sql_query=" ~sql_query ) }}
 
     {% set results = run_query(sql_query) %}
 
     {% if execute %}
       -- we put the roles in a list ...
       {% set role_list = results.columns[0].values() %}
       {{ print ( "role_list_execute=" ~role_list ) }}
     {% else %}
       {% set role_list = [] %}
       {{ print ( "role_list_else=" ~role_list ) }}
     {% endif %}
   {% endfor %}
 {%- endmacro -%}

```

---

<div class="post-metadata">

**Author:** ![Gyom](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Gyom](https://discourse.getdbt.com/u/Gyom)\
**Post date:** [August 23, 2024, 3:13pm UTC](https://discourse.getdbt.com/t/dbt-was-unable-to-infer-all-dependencies-for-the-model-on-run-end/15108/3 "2024-08-23T15:13:25Z")

</div>

Hi,  
Thanks for your advice, but unfortunately I already tried and the result remains the same ☹
