-
Notifications
You must be signed in to change notification settings - Fork 79
Closed
Description
Overview
We have a project where we sometimes run dbt run-operation some_macro and the some_macro being run uses ref somewhere inside it. This ends up calling dbt_unit_testing's running_unit_test(), which checks for tags in the config.
This is fine when config is a model's config. But it does not work when no model is being compiled, because in the latter scenario, config has no "tags" at all.
How to reproduce
In a project set up with dbt_unit_testing run:
> dbt run-operation ref --args "model_name: any_existing_model"
...
argument of type 'NoneType' is not iterable
...Suggestion 1
My recommendation is to edit this macro:
dbt-unit-testing/macros/tests.sql
Lines 179 to 181 in 3bfdb45
| {% macro running_unit_test() %} | |
| {{ return ('unit-test' in config.get('tags')) }} | |
| {% endmacro %} |
to this:
{% macro running_unit_test() %}
{{ return (config.model.resource_type.value == 'model' and 'unit-test' in config.get('tags')) }}
{% endmacro %}Suggestion 2
A simpler (and arguably safer) solution is:
{% macro running_unit_test() %}
{{ return (config.get('tags') and 'unit-test' in config.get('tags')) }}
{% endmacro %}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels