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

Users should always call adapter.drop_relation instead of calling {{ drop_relation() }} directly #221

Open
jtcohen6 opened this issue May 22, 2024 · 0 comments

Comments

@jtcohen6
Copy link
Contributor

Adapter maintainers and users should always call either:

  • adapter.drop_relation
  • drop_relation_if_exists (syntactic sugar that checks cache first, and then calls adapter.drop_relation)

Why? Calling {{ drop_relation() }} directly does not update the cache!! That happens within the adapter drop_relation method here:

def drop_relation(self, relation):
if relation.type is None:
raise RelationTypeNullError(relation)
self.cache_dropped(relation)
self.execute_macro(DROP_RELATION_MACRO_NAME, kwargs={"relation": relation})

Even though this method ultimately shells out to a macro called {{ drop_relation() }}:

{% macro drop_relation(relation) -%}
{{ return(adapter.dispatch('drop_relation', 'dbt')(relation)) }}
{% endmacro %}
{% macro default__drop_relation(relation) -%}
{% call statement('drop_relation', auto_begin=False) -%}
{{ get_drop_sql(relation) }}
{%- endcall %}
{% endmacro %}

Proposals

  • Document this for adapter maintainers and users (https://docs.getdbt.com/reference/dbt-jinja-functions/adapter#drop_relation)
  • Deprecate/remove/rename {{ drop_relation() }}, either by calling dispatch directly in the adapter method or renaming this macro so that it is more clearly returning adapter.dispatch(DROP_RELATION_MACRO_NAME) and not a macro that should be called directly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant