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

Add if execute check within _is_relation #833

Closed
jtcohen6 opened this issue Sep 8, 2023 · 3 comments
Closed

Add if execute check within _is_relation #833

jtcohen6 opened this issue Sep 8, 2023 · 3 comments
Labels
enhancement New feature or request Stale triage

Comments

@jtcohen6
Copy link
Contributor

jtcohen6 commented Sep 8, 2023

Context: dbt-labs/dbt-core#7024 (comment)

Describe the feature

More consistent behavior in _is_relation at parse time, to avoid raising confusing errors.

It's quite common to call get_relation or load_cached_relation, and then pass it into a macro that validates the input via _is_relation. That validation can't happen at parse time — because dbt hasn't yet connected to the database and doesn't yet have access to the adapter/relation cache, those methods return None instead of a Relation object.

I'd propose updating the logic of _is_relation to check if execute before raising an exception. Something like:

{% macro _is_relation(obj, macro) %}
    {%- if execute and not (obj is mapping and obj.get('metadata', {}).get('type', '').endswith('Relation')) -%}
        {%- do exceptions.raise_compiler_error("Macro " ~ macro ~ " expected a Relation but received the value: " ~ obj) -%}
    {%- endif -%}
{% endmacro %}

We should probably do the same for _is_ephemeral, since refs don't actually resolve at parse time either. (They will return a Relation object, but it's a pointer to this model, not the actually referenced model.)

Describe alternatives you've considered

Who will this benefit?

Anyone using introspective dbt_utils macros who don't yet understand the finer nuances of the adapter cache + parsing vs. compilation vs. runtime (internal docs)

Are you interested in contributing this feature?

sure!

@vinit2107
Copy link

Linking #817
I think it's the same issue.

Copy link

github-actions bot commented Mar 9, 2024

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 9, 2024
Copy link

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 Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Stale triage
Projects
None yet
Development

No branches or pull requests

2 participants