Skip to content

Commit 72d9576

Browse files
committed
get_model_relation_for_test: bugfix
1 parent 1177b5e commit 72d9576

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

macros/edr/tests/test_utils/get_model_relation_for_test.sql

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
{% macro get_model_relation_for_test(test_model, test_node) %}
2-
{% set depends_on_node_ids = test_node.get("depends_on", {}).get("nodes") %}
3-
{% if depends_on_node_ids and depends_on_node_ids | length == 1 %}
4-
{% set node = elementary.get_node(depends_on_node_ids[0]) %}
5-
{% do return(elementary.get_relation_from_node(node)) %}
6-
{% endif %}
7-
82
{# If the test model is not a string, then return as-is #}
93
{% if test_model is not string %}
104
{% do return(test_model) %}
115
{% endif %}
126

7+
{# If the test depends on a single model ID, try to get the relation from it #}
8+
{% set depends_on_node_ids = test_node.get("depends_on", {}).get("nodes") %}
9+
{% if depends_on_node_ids and depends_on_node_ids | length == 1 %}
10+
{% set node = elementary.get_node(depends_on_node_ids[0]) %}
11+
{% set relation = elementary.get_relation_from_node(node) %}
12+
{% if relation %}
13+
{% do return(relation) %}
14+
{% endif %}
15+
{% endif %}
16+
1317
{# Test model is a string, this might mean that a "where" parameter was passed to the test.
1418
In the heuristic below we rely on the fact that in this case the model jinja will have
1519
a very specific structure (see the "build_model_str" function in dbt-core) #}

0 commit comments

Comments
 (0)