-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Is there an existing feature request for this?
- I have searched the existing issues
Describe the Feature
When I declare a variable in a dbt_project file, I sometimes need to use it in the same file. For example:
vars:
special_schema: "my_special_schema"
models:
my_staging_models:
staging:
+materialized: view
common:
+enabled: true
+schema: "{{ var('my_special_schema') }}"special_schema is declared in the project-level vars because I need it in several places. I also need to specify this schema as the schema for some models. Currently when I do the above, I get an error:
Compilation Error
Could not render {{ var('my_special_schema') }}: Required var 'my_special_schema' not found in config:
Vars supplied to = {}
Describe alternatives you've considered
Currently, I am adding a config block to every model to specify the schema, and that works, but with many models, it gets very repetitive. It would be nice to specify the schema once (using a variable), in the project file, and not have to do it again.
I suppose I could also include --vars "my_special_schema: some_schema" when running DBT, but for ease of use by others, I'd prefer to use the vars: block in the project file. We have many variables, and there are a few more I'd like to use in this way. Passing them all from the CLI makes for messier scripts.
Who will this benefit?
Everyone who wants to make use of variables in the project file, for variables that are declared in the project file.
Are you interested in contributing this feature?
Yes, but I'm not sure I have the necessary skills or time.
Anything else?
No response