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

_is_relation macro fails for relations from adapter.get_relation on Bigquery. #817

Closed
1 of 5 tasks
PBalsdon opened this issue Jul 28, 2023 · 2 comments
Closed
1 of 5 tasks
Labels
bug Something isn't working triage

Comments

@PBalsdon
Copy link

Describe the bug

If we define a relation from the adapter.get_relation macro, it causes a compiler error in the {{ dbt_utils._is_relation() }} macro. This is in Bigquery. I've tried it in various versions of dbt-utils and dbt

Steps to reproduce

Make a file with the following code

{% set relation=adapter.get_relation(
      database=target.database,
      schema=target.schema,
      identifier="stg_dates" ## REPLACE WITH AN EXISTING MODEL ##
) -%}

{{relation is mapping}} -- Returns True
{{ dbt_utils._is_relation(relation, 'test_call') }}

Compile this file.

Expected results

No errors, the file compiles with True -- Returns True

Actual results

Compiler error
image

Screenshots and log output

System information

The contents of your packages.yml file:

packages:
  - package: dbt-labs/dbt_utils
    version: 1.1.1

Which database are you using dbt with?

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

The output of dbt --version:
dbt cloud:
image

Additional context

I originally discovered this as a bug in audit_helper, but isolated the issue to this macro in dbt_utils.

Are you interested in contributing the fix?

In theory, yes - in reality I have no idea what's going on here and it's baffling me.

@PBalsdon PBalsdon added bug Something isn't working triage labels Jul 28, 2023
@vinit2107
Copy link

vinit2107 commented Sep 10, 2023

Hi @PBalsdon ,
You want DBT to execute the dbt_utils._is_relation only when you run the code. You can control it by wrapping the code around {% if execute %} block, something like this.

{% set relation=adapter.get_relation(
      database=target.database,
      schema=target.schema,
      identifier="stg_dates" ## REPLACE WITH AN EXISTING MODEL ##
) -%}

{{relation is mapping}} -- Returns True
{% if execute %}
{{ dbt_utils._is_relation(relation, 'test_call') }}
{% endif %}

If my understanding is correct, you will have relation only after you execute your script. More documentation here.
Let me know if it solves your issue.

@PBalsdon
Copy link
Author

PBalsdon commented Nov 7, 2023

Thank you, I believe you are correct that we need the if execute. this solved my issue

@PBalsdon PBalsdon closed this as completed Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants