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

0.19.1 unable to infer dependencies for custom tests #3229

Closed
1 of 5 tasks
bmwilly opened this issue Apr 6, 2021 · 7 comments · Fixed by #3272
Closed
1 of 5 tasks

0.19.1 unable to infer dependencies for custom tests #3229

bmwilly opened this issue Apr 6, 2021 · 7 comments · Fixed by #3272
Assignees
Labels
bug Something isn't working regression
Milestone

Comments

@bmwilly
Copy link

bmwilly commented Apr 6, 2021

Describe the bug

I have a macro test_valid_code defining a custom test that uses {{ ref('model') }}. For dbt 0.19.1 (this only fails for 0.19.1), dbt compile gives

Encountered an error:
Runtime Error
  Compilation Error in test valid_code (models/model.yml)
    dbt was unable to infer all dependencies for the model "valid_code_model".
    This typically happens when ref() is placed within a conditional block.

    To fix this, add the following hint to the top of the model "valid_code_model":

    -- depends_on: {{ ref('model') }}

    > in macro test_valid_code (macros/tests/test_valid_code.sql)
    > called by test valid_code_model (models/model.yml)
    > called by test valid_code_model (models/model.yml)

Trying to add -- depends_on: {{ ref('model') }} to the model and/or test file doesn't help.

Expected behavior

dbt {compile,run} to not give any errors.

System information

Which database are you using dbt with?

  • postgres
  • redshift
  • bigquery
  • snowflake
  • other (specify: ____________)

The output of dbt --version:

$ dbt --version
installed version: 0.19.1
   latest version: 0.19.1

Up to date!

Plugins:
  - bigquery: 0.19.1
  - snowflake: 0.19.1
  - redshift: 0.19.1
  - postgres: 0.19.1

The operating system you're using:

macOS 11.2.3

The output of python --version:

Python 3.8.5

@bmwilly bmwilly added bug Something isn't working triage labels Apr 6, 2021
@jtcohen6 jtcohen6 added regression and removed triage labels Apr 6, 2021
@jtcohen6
Copy link
Contributor

jtcohen6 commented Apr 6, 2021

@bmwilly Thanks for the report! It does look like this represents a regression from v0.19.0.

Could you clarify what {{ ref('model') }} represents here? Is that the model that the test is being defined on? If so, this could just be {{ model }} instead (as the built-in schema tests have it).

If this represents a different model that is being directly referenced from within your schema test definition, then I've been able to reproduce this error:

{% macro test_valid_code(model) %}

    select count(*) from (

        select * from {{ model }}
        union all
        select * from {{ ref('model_b') }}
        
    )

{% endmacro %}
Compilation Error in test valid_code_model_a_ (models/schema.yml)
  dbt was unable to infer all dependencies for the model "valid_code_model_a_".
  This typically happens when ref() is placed within a conditional block.

  To fix this, add the following hint to the top of the model "valid_code_model_a_":

  -- depends_on: {{ ref('model_b') }}

  > in macro test_valid_code (macros/test_valid_code.sql)
  > called by test valid_code_model_a_ (models/schema.yml)
  > called by test valid_code_model_a_ (models/schema.yml)

Here's one way to work around this in the meantime, so that the dependency is still detected:

{% macro test_valid_code(model, other_model) %}

    select count(*) from (

        select * from {{ model }}
        union all
        select * from {{ other_model }}
        
    ) validation_errors

{% endmacro %}
version: 2

models:
  - name: model_a
    tests:
      - valid_code:
          other_model: "{{ ref('model_b') }}"

The latter construction is what I'd recommend for generic/schema tests, anyhow. That said, we'll investigate and see if we can figure a way to restore the previous behavior.

@bmwilly
Copy link
Author

bmwilly commented Apr 7, 2021

@jtcohen6 thanks for the quick response and for the understanding from my not very clear report!

If this represents a different model that is being directly referenced from within your schema test definition, then I've been able to reproduce this error:

yes, I did mean a different model that is being directly referenced in the schema test definition, similar to the example you give.

I was able to fix this using your workaround — thanks!

Feel free to close this issue; I'll leave it open in case you want to use it to track restoring the previous functionality.

@jtcohen6
Copy link
Contributor

jtcohen6 commented Apr 29, 2021

@bmwilly We're including a fix for this in v0.19.2, for which we just cut a release candidate. Any chance you could test locally and confirm that it fixes the issue you described above?

pip install dbt==0.19.2rc1
# or
brew install dbt@0.19.2-rc1

@bmwilly
Copy link
Author

bmwilly commented Apr 29, 2021

@jtcohen6 seems to work, thanks!

@MartinNowak
Copy link

pip install dbt==0.19.2rc1
# or
brew install dbt@0.19.2-rc1

@jtcohen6 works if the test is in the same package, but apparently still fails with tests from another package.

@jtcohen6
Copy link
Contributor

jtcohen6 commented May 10, 2021

Thanks for the report @MartinNowak! I wonder if you're seeing the same error as the one reported over in #3324?

@MartinNowak
Copy link

Thanks for the report @MartinNowak! I wonder if you're seeing the same error as the one reported over in #3324?

Thx for reproducing and appending, indeed it's sth. in between the two problems.
#3324 (comment)

iknox-fa pushed a commit that referenced this issue Feb 8, 2022
iknox-fa pushed a commit that referenced this issue Feb 8, 2022
cdugeai added a commit to DITP-pilotage/pilote-2 that referenced this issue Dec 1, 2023
issue: dbt-labs/dbt-core#3229
solution: given by dbt cli when error
cdugeai added a commit to DITP-pilotage/pilote-2 that referenced this issue Dec 1, 2023
* dbt.model.new: df1_indic et df1_ch

Ajout de ces models pour changer facilement les tables d'exposition (indicateur et chantier)

* dbt.model.new: df1_indic et df1_ch

Ajout de ces models pour changer facilement les tables d'exposition (indicateur et chantier)

* fix empty array

* fix: directions_administration_centrale

on récupère correctement les directions_administration_centrale à l'aide de la table metadata_porteur et non plus dans la colonne porteur_shorts_DAC de metadata_chantier qui était présente pour information donc sur laquelle il ne faut pas se baser.

* replace dy dbt ref

* dbt.model.new: df1_indic et df1_ch

Ajout de ces models pour changer facilement les tables d'exposition (indicateur et chantier)

* fix empty array

* fix: directions_administration_centrale

on récupère correctement les directions_administration_centrale à l'aide de la table metadata_porteur et non plus dans la colonne porteur_shorts_DAC de metadata_chantier qui était présente pour information donc sur laquelle il ne faut pas se baser.

* replace dy dbt ref

* update dbt tests

* fix tests

issue: dbt-labs/dbt-core#3229
solution: given by dbt cli when error
cdugeai added a commit to DITP-pilotage/pilote-2 that referenced this issue Dec 4, 2023
* dbt.model.new: df1_indic et df1_ch

Ajout de ces models pour changer facilement les tables d'exposition (indicateur et chantier)

* dbt.model.new: df1_indic et df1_ch

Ajout de ces models pour changer facilement les tables d'exposition (indicateur et chantier)

* fix empty array

* fix: directions_administration_centrale

on récupère correctement les directions_administration_centrale à l'aide de la table metadata_porteur et non plus dans la colonne porteur_shorts_DAC de metadata_chantier qui était présente pour information donc sur laquelle il ne faut pas se baser.

* replace dy dbt ref

* dbt.model.new: df1_indic et df1_ch

Ajout de ces models pour changer facilement les tables d'exposition (indicateur et chantier)

* fix empty array

* fix: directions_administration_centrale

on récupère correctement les directions_administration_centrale à l'aide de la table metadata_porteur et non plus dans la colonne porteur_shorts_DAC de metadata_chantier qui était présente pour information donc sur laquelle il ne faut pas se baser.

* replace dy dbt ref

* update dbt tests

* fix tests

issue: dbt-labs/dbt-core#3229
solution: given by dbt cli when error
cdugeai added a commit to DITP-pilotage/pilote-2 that referenced this issue Dec 4, 2023
* fix directeurs_administration_centrale

on corrige directeurs_administration_centrale

fix directeurs_administration_centrale (2)

* Cohabitation df1-df3 + fix df3_chantier (#671)

* dbt.model.new: df1_indic et df1_ch

Ajout de ces models pour changer facilement les tables d'exposition (indicateur et chantier)

* dbt.model.new: df1_indic et df1_ch

Ajout de ces models pour changer facilement les tables d'exposition (indicateur et chantier)

* fix empty array

* fix: directions_administration_centrale

on récupère correctement les directions_administration_centrale à l'aide de la table metadata_porteur et non plus dans la colonne porteur_shorts_DAC de metadata_chantier qui était présente pour information donc sur laquelle il ne faut pas se baser.

* replace dy dbt ref

* dbt.model.new: df1_indic et df1_ch

Ajout de ces models pour changer facilement les tables d'exposition (indicateur et chantier)

* fix empty array

* fix: directions_administration_centrale

on récupère correctement les directions_administration_centrale à l'aide de la table metadata_porteur et non plus dans la colonne porteur_shorts_DAC de metadata_chantier qui était présente pour information donc sur laquelle il ne faut pas se baser.

* replace dy dbt ref

* update dbt tests

* fix tests

issue: dbt-labs/dbt-core#3229
solution: given by dbt cli when error

* hotfix: Revert "feat: ajout de la météo dans import massif de commentaires (000)"

This reverts commit 526bfc6.

* compare ta_ch et ta_indic

* compute_ta_indic: add 2 rules

2 rules:
- si hausse et va>=vc -> 100%
- si baisse et va<=vc -> 100%

* fix: handle ta=nouveau_ta

then ratio will be 0

* update dump scripts

* Update .gitignore

* Update README.md

* update migration process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants