-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) Cosmos virtualenv operators are using the system dbt instead of the virtualenv dbt. Create a test case that illustrates issue #1246. This test fails with Cosmos 1.7 (and the current main branch) and passes when using PR #1252. This PR also introduces two refactors: - Reuse the parent class method where applicable, as opposed to re-writing it completely - Force the Virtualenv invocation mode to be `SUBPROCESS ` since Airflow/Cosmos are not able to import dbt as a library if it is not part of the same Python virtualenv
- Loading branch information
Showing
3 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
from datetime import datetime | ||
from pathlib import Path | ||
|
||
from airflow.models import DAG | ||
|
||
from cosmos import ProfileConfig | ||
from cosmos.operators.virtualenv import DbtSeedVirtualenvOperator | ||
from cosmos.profiles import PostgresUserPasswordProfileMapping | ||
|
||
DEFAULT_DBT_ROOT_PATH = Path(__file__).parent / "dbt" | ||
DBT_PROJ_DIR = Path(os.getenv("DBT_ROOT_PATH", DEFAULT_DBT_ROOT_PATH)) / "jaffle_shop" | ||
|
||
profile_config = ProfileConfig( | ||
profile_name="default", | ||
target_name="dev", | ||
profile_mapping=PostgresUserPasswordProfileMapping( | ||
conn_id="example_conn", | ||
profile_args={"schema": "public"}, | ||
), | ||
) | ||
|
||
with DAG("example_virtualenv_mini", start_date=datetime(2022, 1, 1)) as dag: | ||
seed_operator = DbtSeedVirtualenvOperator( | ||
profile_config=profile_config, | ||
project_dir=DBT_PROJ_DIR, | ||
task_id="seed", | ||
dbt_cmd_flags=["--select", "raw_customers"], | ||
install_deps=True, | ||
append_env=True, | ||
py_system_site_packages=False, | ||
py_requirements=["dbt-postgres"], | ||
virtualenv_dir=Path("/tmp/persistent-venv2"), | ||
) | ||
seed_operator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters