Lisa Cloutier
06/16/2023, 5:19 PM.
└── workspace/
├── .env
├── dagster/
│ ├── __init__.py
│ ├── assets
│ └── dbt_run.py
└── dbt/
├── dbt_project.yml
└── config/
└── profiles.yml
Contents of .env (sanitized):
DAGSTER_DEPLOYMENT=local
DATABASE_PASSWORD=<my_password>
DATABASE_ROLE=<my_role>
DATABASE_SCHEMA=<my_schema>
DATABASE_USER=<my_user>
profiles.yml contents:
company:
outputs:
dev:
account: <my_snowflake_account>
database: <my_database>
password: "{{ env_var('DBT_DATABASE_PASSWORD') }}" <-- this works when plain text, does not work when set as an env_var
role: <my_role>
schema: <my_schema>
threads: 4
type: snowflake
user: <my_user>
warehouse: <my_warehouse>
__init__.py to set up dbt (from the example, again, this works when the password is in plain text, does not work when I try to use the environment variable)
from dagster_dbt import load_assets_from_dbt_project
from dagster import file_relative_path
import os
DBT_DATABASE_PASSWORD = os.getenv("DATABASE_PASSWORD") <-- my attempt to load the env_var in Dagster first, this didn't work
DBT_PROJECT_PATH = file_relative_path(__file__, "../../dbt/")
DBT_PROFILES = file_relative_path(__file__, "../../dbt/config")
dbt_assets = load_assets_from_dbt_project(
project_dir=DBT_PROJECT_PATH, profiles_dir=DBT_PROFILES, key_prefix=["company"]
)
owen
06/16/2023, 9:40 PMDBT_DATABASE_PASSWORD
, but have it set as DATABASE_PASSWORD
in your .env
file? I believe if you updated your profiles.yml to have
password: "{{ env_var('DATABASE_PASSWORD') }}"
then things would start working.
If you do want to stick with the two separate names approach, you'll want to do something like this in your init file:
# copy the value of DATABASE_PASSWORD to DBT_DATABASE_PASSWORD
os.environ["DBT_DATABASE_PASSWORD"] = os.getenv("DATABASE_PASSWORD")
Lisa Cloutier
06/16/2023, 10:14 PMowen
06/16/2023, 10:48 PMowen
06/16/2023, 10:48 PMdagster dev ...
, is that being executed in the workspace
folder?Lisa Cloutier
06/19/2023, 2:02 AMowen
06/21/2023, 6:26 PMdagster dev
(that spits out a lot of output, so you might want to make it more obvious with some print("-"*200)
nearby or something)