rbachkaniwala
rbachkaniwala

Reputation: 59

Passing list of Relation object to dbt_utils.union_relation macro fails

Related to dbt and jinja2

I am using union_relations from dbt_utils package (0.5.0).

I created my macro which takes list of fully qualified name (like database.schema.identifier) splits it and uses api.Relations.create (link) to create a relation and append each relation to a list.

{{ list_of_relation }} is given to dbt_utils.union_relations(as relations=my_macro([list of fully qualified names])), it's giving me an _is_relation error, I did use log to debug and see if it actually creates a relation and it does. What could be wrong?

Upvotes: 1

Views: 2206

Answers (1)

Jacob Beck
Jacob Beck

Reputation: 63

It sounds like you have a macro written something like this:

{% macro my_macro(names) %}
  {% set list_of_relations = [] %}
  {% for name in names %}
    {% set relation = something(name) %}
    {% do list_of_relations.append(relation) %}
  {% endfor %}
  {{ list_of_relations }}
{% endmacro %}

Instead of using {{ list_of_relation }}, you’ll want {{ return(list_of_relation) }} or {% do return(list_of_relation) %}. The problem is that {{ ... }} turns things into strings in jinja macros, and macros by default return strings.

The documentation on return is here.

Upvotes: 5

Related Questions