-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed as not planned
Labels
enhancementNew feature or requestNew feature or requeststaleIssues that have gone staleIssues that have gone stale
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
When using sources, the generate_database_name override doesn't apply to sources.
Expected Behavior
Sources would take the overridden database name, just like models.
This is either a very big oversight, or for some reason it's intentional. It's quite a blocker for me though. I've tried to get around it by adding some jinja in my sources yaml block, but no luck so far. I'm even trying to call macros from there, which I don't think is possible.
I suppose leaving database explicitly unset might be an OK workaround, as it would take the database of the session which most of the time would be correct.
Steps To Reproduce
- Set up a dbt project
- Configure a source and a model that consumes the source.
- Add a
generate_database_nameoverride macro. Here's an example:
{% macro generate_database_name(custom_database_name=none, node=none) -%}
{%- if custom_database_name is not none and node.resource_type in ['seed', 'model'] -%}
{%- set error_message -%}
{{ node.resource_type | capitalize }} '{{ node.unique_id }}' has a database configured. This is not allowed because the it will be derived from the directory structure and target name.
{%- endset -%}
{{ exceptions.raise_compiler_error(error_message) }}
{%- endif -%}
{% set path = node.path %}
{% set database = path.split('/')[0] %}
{% if target.name in ['prod_us', 'prod_eu'] %}
{{ database }}
{% else %}
{{ database + "_" + target.name }}
{% endif %}
{%- endmacro %}
dbt compile- The compiled models will have whatever db is set in your profile, instead of the overridden one from the macro
Relevant log output
No response
Environment
- OS: macOS
- Python: 3.7.9
- dbt:
❯ dbt --version
installed version: 1.0.2
latest version: 1.0.2
Up to date!
Plugins:
- snowflake: 1.0.0 - Up to date!
### What database are you using dbt with?
snowflake
### Additional Context
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requeststaleIssues that have gone staleIssues that have gone stale