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

Support overriding internal macros from root projects #2301

Closed
drewbanin opened this issue Apr 7, 2020 · 4 comments · Fixed by #2686
Closed

Support overriding internal macros from root projects #2301

drewbanin opened this issue Apr 7, 2020 · 4 comments · Fixed by #2686
Labels
bug Something isn't working

Comments

@drewbanin
Copy link
Contributor

Describe the bug

Users should be able to override plugin-specific macros from their root project.

Steps To Reproduce

{# macros/override.sql #}

{% macro postgres__get_columns_in_relation() %}

    {{ log("OVERRIDE", info=true) }}

{% endmacro %}
-- models/my_model.sql

{{ adapter.get_columns_in_relation(this) }}

I'd expect to see log output indicating that the override macro was being used. This does not work for macros named get_columns_in_relation or postgres__get_columns_in_relation.

I haven't done enough digging to know why this behavior would be different from something like create_table_as, but I suspect it has something to do with going through the context used by the adapter.get_* methods.

Expected behavior

Macros defined in a project should override dbt's core implementation, or the implementation provided by a dbt plugin.

The output of dbt --version:

0.16.0
@drewbanin drewbanin added the bug Something isn't working label Apr 7, 2020
@beckjake
Copy link
Contributor

beckjake commented Apr 7, 2020

This happens because adapter.get_columns_in_relation doesn't take a manifest, so it doesn't pass a manifest to execute_macro, so execute_macro uses the "internal manifest", which only has macros from core.

We might be able to avoid this by parsing all project macros up-front and building that into the "internal manifest". I feel a lot more comfortable with that path now that we've refactored manifest loading quite a bit.

The tricky part of that is the easy path here is probably going to involve running load_all_projects twice, which irks me.

@ArtiJain0688
Copy link

Hello Jacob,

I am trying to override some macros with respect to "Snapshot" materialization. As you mentioned in the above issue even though I have overwritten the macros it still reads from the core.
Could you please tell me steps how to override this behaviour so that the code reads the overwritten macros and functions according to the changes made in it

@jtcohen6
Copy link
Contributor

@ArtiJain0688 Could you provide some more details of your implementation? Which version of dbt are you using? Which macro in the snapshot materialization are you trying to override, and how have you gone about it? As long as you have defined a macro in your own project with the same name as a macro in dbt-core or a dbt adapter plugin, dbt should know to prefer yours.

@ArtiJain0688
Copy link

ArtiJain0688 commented Mar 18, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants