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

Can't invoke list_relations_without_caching from a macro #390

Closed
voroninman opened this issue Aug 30, 2023 · 5 comments
Closed

Can't invoke list_relations_without_caching from a macro #390

voroninman opened this issue Aug 30, 2023 · 5 comments

Comments

@voroninman
Copy link
Contributor

voroninman commented Aug 30, 2023

{{ adapter.list_relations_without_caching(schema_relation) }} fails with 'dbt.context.providers.RuntimeDatabaseWrapper object' has no attribute 'list_relations_without_caching'.

dbt-athena-community==1.6.0
dbt-core==1.6.1
@voroninman
Copy link
Contributor Author

voroninman commented Aug 30, 2023

I'm new here. Will #391 fix it?

@nicor88
Copy link
Contributor

nicor88 commented Aug 30, 2023

@voroninman can you copy here the macro that you are trying to use? yes #391 should make the method adapter.list_relations_without_caching available to be used in a macro.

@voroninman
Copy link
Contributor Author

@voroninman can you copy here the macro that you are trying to use? yes #391 should make the method adapter.list_relations_without_caching available to be used in a macro.

Thanks for a quick reply! Below is the macro that I'm currently working on.

{% macro drop_created_playground_schemas() %}
    {% if "playground" not in target.schema %}
        {{ exceptions.raise_compiler_error("Should never be run outside a playground target.") }}
    {% endif %}

    {% set query_affected_schemas %}
        SELECT DISTINCT schema_name
        FROM awsdatacatalog.information_schema.schemata
        WHERE schema_name LIKE '{{ target.schema }}%'
    {% endset %}

    {% set result = run_query(query_affected_schemas) %}

    {% for row in result %}
        {% set schema_name = row.get('schema_name') %}
        {% set schema_relation = api.Relation.create(database=target.database, schema=schema_name) %}

        -- We drop relations to make sure we actually delete all s3 objects related to the schema
        {% do log('Dropping relations in schema: ' ~ schema_relation, info=True) %}
        {% set relations = adapter.list_relations_without_caching(schema_relation) %}
        {% for relation in relations %}
            {% do log('\tDropping: ' ~ relation.get('name'), info=True) %}
            {% do dbt.drop_relation(adapter.get_relation(
                database=relation.get('database'),
                schema=relation.get('schema'),
                identifier=relation.get('name'),
            )) %}
        {% endfor %}

        {% do log('Dropping schema: ' ~ schema_relation, info=True) %}
        {% do drop_schema(schema_relation) %}
    {% endfor %}
{% endmacro %}

@nicor88
Copy link
Contributor

nicor88 commented Aug 30, 2023

Thanks, I merged your PR, you can try to install the latest version of the adapter from main and see if it works.

@voroninman
Copy link
Contributor Author

Thanks, I merged your PR, you can try to install the latest version of the adapter from main and see if it works.

Already did. It works as expected. Thanks a lot!

Fixed by #391.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants