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

Provide an interface to throw warnings #1970

Closed
clrcrl opened this issue Dec 3, 2019 · 2 comments · Fixed by #1977
Closed

Provide an interface to throw warnings #1970

clrcrl opened this issue Dec 3, 2019 · 2 comments · Fixed by #1977
Labels
enhancement New feature or request
Milestone

Comments

@clrcrl
Copy link
Contributor

clrcrl commented Dec 3, 2019

Describe the feature

Currently, we have a jinja interface to throw a compilation error, exceptions:

  {{ exceptions.raise_compiler_error("Invalid `number`. Got: " ~ number) }}

I want a similar interface to throw warnings. Preferably, these warnings should fail when the --warn-error flag is used.

My particular use case is to throw warnings for macros in dbt-utils that are being deprecated (see here).

Describe alternatives you've considered

Here's how I currently do it:

    {% if execute %}
        {{ log("Warning: the `get_tables_by_prefix` macro is no longer supported and will be deprecated in a future release of dbt-utils. Use the `get_relations_by_prefix` macro instead", info=True) }}
    {% endif %}

Note that the warning is wrapped in an execute so that dbt doesn't log this when parsing the project (including macros).

Who will this benefit?

Package maintainers.

@clrcrl clrcrl added enhancement New feature or request triage labels Dec 3, 2019
@clrcrl
Copy link
Contributor Author

clrcrl commented Dec 3, 2019

From Drew:

I think the easier path is to export the warn_or_error method (or something similar with maybe a clearer name): https://github.com/fishtown-analytics/dbt/blob/dev/0.15.1/core/dbt/exceptions.py#L740
The big difference between a Deprecation and just calling warn_or_error is that a deprecation warning will only be shown once even if that deprecation is “warned” multiple times. If that’s beneficial for the macro use case then we can figure out how to make it happen. If it’s not necessary then there are other simpler options here too

@drewbanin drewbanin removed the triage label Dec 3, 2019
@drewbanin drewbanin added this to the 0.15.2: Barbara Gittings milestone Dec 3, 2019
@drewbanin
Copy link
Contributor

drewbanin commented Dec 3, 2019

I just prioritized this issue for the 0.15.1 release

beckjake added a commit that referenced this issue Dec 5, 2019
…-context

add exceptions.warn to the dbt context (#1970)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants