Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'except' is undefined #121

Closed
mahdimostafalighthouselabs opened this issue Mar 1, 2023 · 6 comments
Closed

'except' is undefined #121

mahdimostafalighthouselabs opened this issue Mar 1, 2023 · 6 comments

Comments

@mahdimostafalighthouselabs
Copy link

mahdimostafalighthouselabs commented Mar 1, 2023

Hello there,

I am trying to build a unit test but seem to get an error. This is my script in the test folder:

{{ config(tags=['unit-test']) }}

{% call dbt_unit_testing.test('intermediate_model','clocktower_tasks') %}
  {% call dbt_unit_testing.mock_ref ('raw_model') %}
     select 1 as users_id
  {% endcall %}

  {% call dbt_unit_testing.expect() %}
    select  1  as users_id
  {% endcall %}

{% endcall %}

and this is the error I get:

 Compilation Error in test raw_unit_test (tests/raw_unit_test.sql)
09:15:41    'except' is undefined
09:15:41    
09:15:41    > in macro build_test_report (macros/tests.sql)
09:15:41    > called by macro test (macros/tests.sql)
09:15:41    > called by macro build_test_queries (macros/tests.sql)

Have I missed something out? or is the build not valid?

@psousa50
Copy link
Collaborator

psousa50 commented Mar 1, 2023

Hi @mahdimostafalighthouselabs , could you please me which database are you using?

@mahdimostafalighthouselabs
Copy link
Author

hi @psousa50 I am using GBQ as my database

@alaneve
Copy link

alaneve commented Mar 14, 2023

I also ran into this (using GBQ). Replacing except() with dbt_utils.except() worked for me and a coworker.

extra_entries as (
select '+' as diff, count, {{columns}} from actual
{{ except() }}
select '+' as diff, count, {{columns}} from expectations),
missing_entries as (
select '-' as diff, count, {{columns}} from expectations
{{ except() }}
select '-' as diff, count, {{columns}} from actual)

Replace above with this

    extra_entries as (
    select '+' as diff, count, {{columns}} from actual
    {{ dbt_utils.except() }}
    select '+' as diff, count, {{columns}} from expectations),

    missing_entries as (
    select '-' as diff, count, {{columns}} from expectations
    {{ dbt_utils.except() }}
    select '-' as diff, count, {{columns}} from actual)

@mahdimostafalighthouselabs
Copy link
Author

@alaneve thank you, this also worked for me!

@alaneve
Copy link

alaneve commented Mar 15, 2023

Looks like issue #88 was flagging the reverse of this and spawned PR #94 which removed the dbt_utils specification.

My team is using dbt 1.0.5, and the migration of except() into dbt-core happened in v1.2.0 (https://github.com/dbt-labs/dbt-core/releases/tag/v1.2.0) to solve their issue 4813 dbt-labs/dbt-core#4813, so it seems like the more recent versions of dbt-core shouldn't have this problem.

If supporting older versions of dbt-core is off the table, I'd think dbt-unit-testing should at least identify the minimum dbt-core version required which appears to be v1.2.0.

@cdiniz
Copy link
Collaborator

cdiniz commented Mar 18, 2023

Hi @alaneve, you're right. We should have flagged and bumped the major version. We'll update the README accordingly.

You could use v0.2.3 while you use older versions of dbt-core.

Thank you for the feedback.

@cdiniz cdiniz closed this as completed Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants