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

compare_relations adapter.get_relation doesn't work as in the README #82

Closed
1 of 5 tasks
christineberger opened this issue Sep 12, 2023 · 7 comments
Closed
1 of 5 tasks
Labels
bug Something isn't working Stale triage
Milestone

Comments

@christineberger
Copy link
Contributor

Describe the bug

The compare_relations macro seems to have an issue with the adapter.get_relation value on the get_filtered_columns_in_relation operation. It seems to work with an {% if execute %} wrapper, though.

Steps to reproduce

Copy the code from the README for compare_relations, then use it as-is, swapping the adapter.get_relations call to an accessible table. Try to run the macro - you will get an error with an empty value.

Expected results

A summarized comparison between the two datasets. Using Benoit's suggestion from an internal channel, the macro works fine like this:

{% set dbt_relation=ref('orders') %}

{% if execute %}
    {%- set old_etl_relation = adapter.get_relation(
        database="ANALYTICS",
        schema="DBT_COHMS",
        identifier="FCT_ORDERS") -%}

    {{ audit_helper.compare_relations(
        a_relation=old_etl_relation,
        b_relation=dbt_relation,
        primary_key="order_id"
    ) }}
{% endif %}

Actual results

With the snippet in the README:
Screenshot 2023-09-12 at 6 01 17 PM

Benoit's version:
Screenshot 2023-09-12 at 6 06 58 PM

System information

The contents of your packages.yml file:
Screenshot 2023-09-12 at 6 08 52 PM

Which database are you using dbt with?

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

The output of dbt --version:
1.6.0 - dbt Cloud

The operating system you're using:
Mac / Arc Browser

The output of python --version:

Additional context

It's fine if things now need to be wrapped in if execute, but the README should reflect!

Are you interested in contributing the fix?

Would love to, but don't have time to solution if needed 🥲

@christineberger christineberger added bug Something isn't working triage labels Sep 12, 2023
Copy link

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

@github-actions github-actions bot added the Stale label Mar 11, 2024
@graciegoheen
Copy link
Contributor

graciegoheen commented Mar 12, 2024

Just ran into the same issue

This works fine:

{% set old_etl_relation=adapter.get_relation(
      database="DEVELOPMENT",
      schema="DBT_GGOHEEN",
      identifier="stg_worlds"
) -%}

{{ old_etl_relation }}

But when I try to call one of the audit helper macros, I get a failure:
Screenshot 2024-03-12 at 2 13 04 PM

@graciegoheen
Copy link
Contributor

I'm not sure how you would create an integration test for this, because building a model works fine - it's just the preview that fails.

@github-actions github-actions bot removed the Stale label Mar 13, 2024
@joellabes
Copy link
Contributor

I think that instead of fixing the readme we can/should fix the various macros!

  • compare_relation_columns from grace's example can be fixed by adding an if execute block in here before trying to get the information_schema off the (nonexistent) Relation
  • compare_relations from christine's example can be fixed in dbt_utils, by moving the existing if execute check in get_filtered_columns_in_relation to before the is_relation check

@graciegoheen graciegoheen added this to the 1.0.0 milestone Apr 2, 2024
Copy link

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

@github-actions github-actions bot added the Stale label Sep 30, 2024
Copy link

github-actions bot commented Oct 8, 2024

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale triage
Projects
None yet
Development

No branches or pull requests

3 participants