Open megetron3 opened 5 months ago
just notified on slack that i must mock macros of the unittest:
adding this solve the issue:
overrides:
macros:
dbt_utils.star: 'ID, SOURCE_PATH, PARTNER'
@dbeatty10, could you kindly reopen this?
I've come to realize that testing a model shouldn't necessarily compel you to mock the macro. Rather, it should be an optional step.
@dbeatty10 Could you reopen this issue? I'm running into the exact same error, but as I used the dbt_utils.star macro more than once to select columns from different models, I couldn't overwrite the macro results like OP did.
See below for a reproducible example that involves at least two calls to dbt_utils.star
that have different outputs. The example is a bit contrived, but I think it demonstrates the issue being raised.
Create these files:
models/my_model_a
select 1 as id, 1 as id_a
models/my_model_b
select 1 as id, 2 as id_b
models/my_model_c
select
a.id,
{{ dbt_utils.star(ref('my_model_a'), except=["id"]) }},
{{ dbt_utils.star(ref('my_model_b'), except=["id"]) }}
from {{ ref('my_model_a') }} as a
inner join {{ ref('my_model_b') }} as b on a.id = b.id
models/_unit_tests.yml
unit_tests:
- name: dbt_core_10254
model: my_model_c
given:
- input: ref('my_model_a')
rows:
- { id: 0, id_b: 123 }
- input: ref('my_model_b')
rows:
- { id: 0, id_c: 456 }
expect:
rows:
- { id: 0, id_b: 123, id_c: 456 }
Run these commands:
dbt run -s +my_model_c
dbt build -s my_model_c
Get this output:
22:47:33 Running with dbt=1.8.6
22:47:33 Registered adapter: postgres=1.8.2
22:47:33 Found 3 models, 533 macros, 1 unit test
22:47:33
22:47:34 Concurrency: 5 threads (target='postgres')
22:47:34
22:47:34 1 of 2 START unit_test my_model_c::dbt_core_10254 .............................. [RUN]
22:47:34 1 of 2 ERROR my_model_c::dbt_core_10254 ........................................ [ERROR in 0.05s]
22:47:34 2 of 2 SKIP relation dbt_dbeatty.my_model_c .................................... [SKIP]
22:47:34
22:47:34 Finished running 1 unit test, 1 view model in 0 hours 0 minutes and 0.36 seconds (0.36s).
22:47:34
22:47:34 Completed with 1 error and 0 warnings:
22:47:34
22:47:34 Compilation Error in unit_test dbt_core_10254 (models/_unit_tests.yml)
The `star` macro cannot be used with ephemeral models, as it relies on the information schema.
`my_model_a` is an ephemeral model. Consider making it a view or table instead.
> in macro _is_ephemeral (macros/jinja_helpers/_is_ephemeral.sql)
> called by macro default__star (macros/sql/star.sql)
> called by macro star (macros/sql/star.sql)
> called by unit_test dbt_core_10254 (models/_unit_tests.yml)
22:47:34
22:47:34 Done. PASS=0 WARN=0 ERROR=1 SKIP=1 TOTAL=2
Is this a new bug in dbt-core?
Current Behavior
When running unit tests that involve the star macro from dbt-utils, I encounter an error indicating that the macro cannot be used with ephemeral models. However, the models in question are all materialized as views, not ephemeral models.
Test fails with error:
Expected Behavior
The test should run successfully without any errors, as the model is materialized as a view.
Steps To Reproduce
Relevant code:
KLARNA.sql
pos__enriched_pc__klarna.sql
sources.yml
Relevant log output
Environment
Which database adapter are you using with dbt?
No response
Additional Context
No response