Nicolas Parot Alvarez
01/27/2023, 9:35 AMprofiles_dir
so it will use the default target defined in pofiles.yml
.
While with the DBT CLI, we can specify a target different from the default by using the --target
parameter.
I think it would be nice to have this target
parameter in the dagster-dbt API.
Our use case is that we have two distinct databases with their own specific DBT assets.
A current workaround is to manage two different profiles_dir
which have each a different profiles.yml
with a different default target.Qwame
01/27/2023, 1:55 PMdbt_cli_resource.configured({'profiles_dir': pathToDir, 'project_dir': pathToproject, 'target': yoirPreferredTarget})
You can now go ahead and use this resource to load your dbt assetsNicolas Parot Alvarez
01/27/2023, 2:39 PMChris Chan
02/07/2023, 3:59 PMload_assets_from_dbt_project
with with_resources
, the resource isn't used when loading assets
You can see this in the dbt command that is run when loading Dagster code (like when dagit starts you can see the dbt command that is run to create the dbt assets). That dbt command doesn't use --target
even if your resource is configured with a target
That matches what I see in the code https://github.com/dagster-io/dagster/blob/master/python_modules/libraries/dagster-dbt/dagster_dbt/asset_defs.py#L63-L68 which doesn't include target
as a flagNicolas Parot Alvarez
02/08/2023, 11:08 AMselect
argument of load_assets_from_dbt_project
.Chris Chan
02/08/2023, 1:45 PMload_assets_from_dbt_project
uses dbt ls ...
to load models as assets (by creating a manifest, then parsing it). Like you said in your original message, if you don't specify a target, dbt uses the default target as specified in your profiles.yml
In my case, I use a different database and credentials for different targets (very common). I don't have the local dev credentials in my production environment. So when Dagster attempts to load models, it fails because it's using the default target and those environment variables don't exist in productionNicolas Parot Alvarez
02/08/2023, 2:53 PMChris Chan
02/08/2023, 2:54 PMWhen Dagit will load your DBT assets, it will load the DBT models you selected, this is independent of the targetthat's what I'm saying, this isn't true. Dagster needs to generate a manifest in order to parse the dbt models into assets. Dagster creates a manifest by running
dbt ls ...
. Any dbt command uses the default target if it isn't specifiedspecifying the target in the dbt resource configThis is working for me. I'm just saying
load_assets_from_dbt_project
isn't strictly speaking independent of any targets, because it's running a dbt CLI command in the background. So if someone, like me, uses environment variables to configure targets, those environment variables need to be provided for the default targetNicolas Parot Alvarez
02/08/2023, 5:03 PMdbt ls
.
I guess the workaround would be to either have a custom DBT profiles.yml
for each environment, or maybe if it's possible, have the value of the target
in profiles.yml
also taken from an environment variable.Rob Martorano
04/24/2023, 7:49 PMtarget
here does work, would the dagster team be open to making target a param? Right now we essentially have forked the load_assets_from_dbt_project
path just to set that param.
for context on why thats currently needed, the bigquery io manager requires the second to last value in the asset key to be the dataset, but we set different datasets in different envs, we use a custom node_info_to_asset_key
to grab the "custom schema" for the asset key but the issue is the custom schema is always for the dbt profile default instead of the proper target