Support custom packages-install-path#1768
Merged
Merged
Conversation
The feature introduced in #1670 (Support running `dbt deps` incrementally to pre-defined `dbt_packages` during task execution) did not work as expected if users had defined a custom path for `packages-install-path`. It only worked if the default (`dbt_packages` was being used. This PR aims to solve the issue.
✅ Deploy Preview for sunny-pastelito-5ecb04 canceled.
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for a custom "packages-install-path" for dbt projects, addressing issues when a non-default path is defined.
- Introduces get_dbt_packages_subpath to determine the package installation subpath.
- Updates tests to verify default and custom paths along with handling invalid YAML.
- Adjusts copy_dbt_packages and create_symlinks to use the new subpath logic.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/dbt/test_project.py | Added tests to ensure proper behavior for default, missing, invalid YAML, and custom paths |
| cosmos/dbt/project.py | New function get_dbt_packages_subpath and updates to file operations with custom paths |
| cosmos/constants.py | Updated constants with DBT_DEFAULT_PACKAGES_FOLDER and DBT_PROJECT_FILENAME |
Deploying astronomer-cosmos with
|
| Latest commit: |
ddab844
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1eb2559f.astronomer-cosmos.pages.dev |
| Branch Preview URL: | https://support-custom-packages-inst.astronomer-cosmos.pages.dev |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1768 +/- ##
=======================================
Coverage 97.70% 97.71%
=======================================
Files 84 84
Lines 5228 5243 +15
=======================================
+ Hits 5108 5123 +15
Misses 120 120 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
pankajkoti
pushed a commit
that referenced
this pull request
May 20, 2025
The feature introduced in #1670 (Support running `dbt deps` incrementally to pre-defined `dbt_packages` during task execution) did not work as expected if users had defined a custom path for `packages-install-path`. It only worked if the default (`dbt_packages` was being used. This PR aims to solve the issue.
pankajkoti
pushed a commit
that referenced
this pull request
May 21, 2025
The feature introduced in #1670 (Support running `dbt deps` incrementally to pre-defined `dbt_packages` during task execution) did not work as expected if users had defined a custom path for `packages-install-path`. It only worked if the default (`dbt_packages` was being used. This PR aims to solve the issue. (cherry picked from commit 62b6ddc)
This was referenced May 21, 2025
Merged
pankajkoti
added a commit
that referenced
this pull request
May 21, 2025
Bug Fixes * Fix ``full_refresh`` parameter in ``AIRFLOW_ASYNC`` ``ExecutionConfig`` mode by @tuantran0910 in #1738 * Fix dbt ls invocation method log message by @tatiana and @dstandish in #1749 * Ensure remote target directory is created when copying files when using local directory by @tuantran0910 and @corsettigyg in #1740 * Support custom ``packages-install-path`` by @tatiana in #1768 * Disable dbt static parser during Airflow task execution using dbt runner by @pankajkoti and @tatiana in #1760 * Fix ``ExecutionMode.LOCAL`` to leverage ``ProjectConfig.manifest_path`` by @tatiana in #1772 * Refactor ``AIRFLOW_ASYNC`` so that the path in the remote object store is specific per DAG run by @tuantran0910 in #1741 * Optimise memory usage with optional explicit imports by @pankajkoti and @tatiana in #1769 Documentation * Fix documentation rendering for ``use_dataset_airflow3_uri_standard`` by @pankajastro in #1742 * Correct custom callback example by @walter9388 in #1747 Others * Re-enable integration tests durations to troubleshoot performance degradation by @tatiana in #1735 * Run listener tests for Airflow 3 by @pankajastro in #1743 * Add Airflow 3 db files to ignore from git tracking by @pankajkoti in #1755 * Log contents of ``packages.yml`` when ``AIRFLOW__LOGGING__LOGGING_LEVEL=DEBUG`` by @tatiana in #1764 * Fix Airflow dependencies in the CI by @tatiana in #1773 * Pre-commit updates: #1744, #1765, #1770
pankajkoti
added a commit
that referenced
this pull request
May 21, 2025
Bug Fixes * Fix ``full_refresh`` parameter in ``AIRFLOW_ASYNC`` ``ExecutionConfig`` mode by @tuantran0910 in #1738 * Fix dbt ls invocation method log message by @tatiana and @dstandish in #1749 * Ensure remote target directory is created when copying files when using local directory by @tuantran0910 and @corsettigyg in #1740 * Support custom ``packages-install-path`` by @tatiana in #1768 * Disable dbt static parser during Airflow task execution using dbt runner by @pankajkoti and @tatiana in #1760 * Fix ``ExecutionMode.LOCAL`` to leverage ``ProjectConfig.manifest_path`` by @tatiana in #1772 * Refactor ``AIRFLOW_ASYNC`` so that the path in the remote object store is specific per DAG run by @tuantran0910 in #1741 * Optimise memory usage with optional explicit imports by @pankajkoti and @tatiana in #1769 Documentation * Fix documentation rendering for ``use_dataset_airflow3_uri_standard`` by @pankajastro in #1742 * Correct custom callback example by @walter9388 in #1747 Others * Re-enable integration tests durations to troubleshoot performance degradation by @tatiana in #1735 * Run listener tests for Airflow 3 by @pankajastro in #1743 * Add Airflow 3 db files to ignore from git tracking by @pankajkoti in #1755 * Log contents of ``packages.yml`` when ``AIRFLOW__LOGGING__LOGGING_LEVEL=DEBUG`` by @tatiana in #1764 * Fix Airflow dependencies in the CI by @tatiana in #1773 * Pre-commit updates: #1744, #1765, #1770 --------- (cherry picked from commit 430be00)
tatiana
added a commit
that referenced
this pull request
Dec 11, 2025
Some dbt projects are generic and are configured in a way that the `packages-install-path` is jinja templated. For example:
```
packages-install-path: 'dbt_packages{{ "_" + env_var("dbt_packages_suffix","") if env_var("dbt_packages_suffix","")!="" }}'
```
When attempting to use this with
- `ProjectConfig.install_dbt_deps=True`
- `ProjectConfig.copy_dbt_packages=True`
Users who have this configuration face the following error:
```
[2025-12-11, 10:54:23 UTC] {local.py:474} INFO - Copying dbt packages to temporary folder.
[2025-12-11, 10:54:23 UTC] {project.py:77} INFO - Copying dbt packages to temporary folder...
[2025-12-11, 10:54:23 UTC] {taskinstance.py:3336} ERROR - Task failed with exception
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 776, in _execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 742, in _execute_callable
return ExecutionCallableRunner(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/utils/operator_helpers.py", line 252, in run
return self.func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/base.py", line 310, in execute
self.build_and_run_cmd(context=context, cmd_flags=self.add_cmd_flags())
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 842, in build_and_run_cmd
result = self.run_command(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 601, in run_command
self._clone_project(tmp_dir_path)
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 475, in _clone_project
copy_dbt_packages(Path(self.project_dir), tmp_dir_path)
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/project.py", line 91, in copy_dbt_packages
shutil.copy2(src_path, dst_path)
File "/usr/local/lib/python3.11/shutil.py", line 448, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/local/lib/python3.11/shutil.py", line 256, in copyfile
with open(src, 'rb') as fsrc:
^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/airflow/dags/dbt/pr_3531_13_dbt_vip_enrichment/dbt_packages{{ "_" + env_var("dbt_packages_suffix","") if env_var("dbt_packages_suffix","")!="" }}'
```
This is because when we implemented #1768 we did not forsee the parameter could be a template.
This PR aims to solve this issue.
tatiana
added a commit
that referenced
this pull request
Dec 12, 2025
Some dbt projects are generic and are configured in a way that the
`packages-install-path` is jinja templated. For example:
```
packages-install-path: 'dbt_packages{{ "_" + env_var("dbt_packages_suffix","") if env_var("dbt_packages_suffix","")!="" }}'
```
When attempting to use this with
- `ProjectConfig.install_dbt_deps=True`
- `ProjectConfig.copy_dbt_packages=True`
Users who have this configuration face the following error:
```
[2025-12-11, 10:54:23 UTC] {local.py:474} INFO - Copying dbt packages to temporary folder.
[2025-12-11, 10:54:23 UTC] {project.py:77} INFO - Copying dbt packages to temporary folder...
[2025-12-11, 10:54:23 UTC] {taskinstance.py:3336} ERROR - Task failed with exception
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 776, in _execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 742, in _execute_callable
return ExecutionCallableRunner(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/utils/operator_helpers.py", line 252, in run
return self.func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/base.py", line 310, in execute
self.build_and_run_cmd(context=context, cmd_flags=self.add_cmd_flags())
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 842, in build_and_run_cmd
result = self.run_command(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 601, in run_command
self._clone_project(tmp_dir_path)
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 475, in _clone_project
copy_dbt_packages(Path(self.project_dir), tmp_dir_path)
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/project.py", line 91, in copy_dbt_packages
shutil.copy2(src_path, dst_path)
File "/usr/local/lib/python3.11/shutil.py", line 448, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/local/lib/python3.11/shutil.py", line 256, in copyfile
with open(src, 'rb') as fsrc:
^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/airflow/dags/dbt/pr_3531_13_dbt_vip_enrichment/dbt_packages{{ "_" + env_var("dbt_packages_suffix","") if env_var("dbt_packages_suffix","")!="" }}'
```
This is because when we implemented
#1768 we did not
forsee the parameter could be a template.
This PR aims to solve this issue.
Observation: we'll need to release this not only as part of 1.12.0, but
also cherry-pick it and, exceptionally, backport it to v1.10.3 and
1.11.3.
tatiana
added a commit
that referenced
this pull request
Dec 16, 2025
Some dbt projects are generic and are configured in a way that the
`packages-install-path` is jinja templated. For example:
```
packages-install-path: 'dbt_packages{{ "_" + env_var("dbt_packages_suffix","") if env_var("dbt_packages_suffix","")!="" }}'
```
When attempting to use this with
- `ProjectConfig.install_dbt_deps=True`
- `ProjectConfig.copy_dbt_packages=True`
Users who have this configuration face the following error:
```
[2025-12-11, 10:54:23 UTC] {local.py:474} INFO - Copying dbt packages to temporary folder.
[2025-12-11, 10:54:23 UTC] {project.py:77} INFO - Copying dbt packages to temporary folder...
[2025-12-11, 10:54:23 UTC] {taskinstance.py:3336} ERROR - Task failed with exception
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 776, in _execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 742, in _execute_callable
return ExecutionCallableRunner(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/utils/operator_helpers.py", line 252, in run
return self.func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/base.py", line 310, in execute
self.build_and_run_cmd(context=context, cmd_flags=self.add_cmd_flags())
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 842, in build_and_run_cmd
result = self.run_command(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 601, in run_command
self._clone_project(tmp_dir_path)
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 475, in _clone_project
copy_dbt_packages(Path(self.project_dir), tmp_dir_path)
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/project.py", line 91, in copy_dbt_packages
shutil.copy2(src_path, dst_path)
File "/usr/local/lib/python3.11/shutil.py", line 448, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/local/lib/python3.11/shutil.py", line 256, in copyfile
with open(src, 'rb') as fsrc:
^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/airflow/dags/dbt/pr_3531_13_dbt_vip_enrichment/dbt_packages{{ "_" + env_var("dbt_packages_suffix","") if env_var("dbt_packages_suffix","")!="" }}'
```
This is because when we implemented
#1768 we did not
forsee the parameter could be a template.
This PR aims to solve this issue.
Observation: we'll need to release this not only as part of 1.12.0, but
also cherry-pick it and, exceptionally, backport it to v1.10.3 and
1.11.3.
(cherry picked from commit 4a906cd)
tatiana
added a commit
that referenced
this pull request
Dec 16, 2025
Some dbt projects are generic and are configured in a way that the
`packages-install-path` is jinja templated. For example:
```
packages-install-path: 'dbt_packages{{ "_" + env_var("dbt_packages_suffix","") if env_var("dbt_packages_suffix","")!="" }}'
```
When attempting to use this with
- `ProjectConfig.install_dbt_deps=True`
- `ProjectConfig.copy_dbt_packages=True`
Users who have this configuration face the following error:
```
[2025-12-11, 10:54:23 UTC] {local.py:474} INFO - Copying dbt packages to temporary folder.
[2025-12-11, 10:54:23 UTC] {project.py:77} INFO - Copying dbt packages to temporary folder...
[2025-12-11, 10:54:23 UTC] {taskinstance.py:3336} ERROR - Task failed with exception
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 776, in _execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 742, in _execute_callable
return ExecutionCallableRunner(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/utils/operator_helpers.py", line 252, in run
return self.func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/base.py", line 310, in execute
self.build_and_run_cmd(context=context, cmd_flags=self.add_cmd_flags())
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 842, in build_and_run_cmd
result = self.run_command(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 601, in run_command
self._clone_project(tmp_dir_path)
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 475, in _clone_project
copy_dbt_packages(Path(self.project_dir), tmp_dir_path)
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/project.py", line 91, in copy_dbt_packages
shutil.copy2(src_path, dst_path)
File "/usr/local/lib/python3.11/shutil.py", line 448, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/local/lib/python3.11/shutil.py", line 256, in copyfile
with open(src, 'rb') as fsrc:
^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/airflow/dags/dbt/pr_3531_13_dbt_vip_enrichment/dbt_packages{{ "_" + env_var("dbt_packages_suffix","") if env_var("dbt_packages_suffix","")!="" }}'
```
This is because when we implemented
#1768 we did not
forsee the parameter could be a template.
This PR aims to solve this issue.
Observation: we'll need to release this not only as part of 1.12.0, but
also cherry-pick it and, exceptionally, backport it to v1.10.3 and
1.11.3.
(cherry picked from commit 4a906cd)
tatiana
added a commit
that referenced
this pull request
Dec 16, 2025
Some dbt projects are generic and are configured in a way that the
`packages-install-path` is jinja templated. For example:
```
packages-install-path: 'dbt_packages{{ "_" + env_var("dbt_packages_suffix","") if env_var("dbt_packages_suffix","")!="" }}'
```
When attempting to use this with
- `ProjectConfig.install_dbt_deps=True`
- `ProjectConfig.copy_dbt_packages=True`
Users who have this configuration face the following error:
```
[2025-12-11, 10:54:23 UTC] {local.py:474} INFO - Copying dbt packages to temporary folder.
[2025-12-11, 10:54:23 UTC] {project.py:77} INFO - Copying dbt packages to temporary folder...
[2025-12-11, 10:54:23 UTC] {taskinstance.py:3336} ERROR - Task failed with exception
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 776, in _execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 742, in _execute_callable
return ExecutionCallableRunner(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/utils/operator_helpers.py", line 252, in run
return self.func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/base.py", line 310, in execute
self.build_and_run_cmd(context=context, cmd_flags=self.add_cmd_flags())
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 842, in build_and_run_cmd
result = self.run_command(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 601, in run_command
self._clone_project(tmp_dir_path)
File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 475, in _clone_project
copy_dbt_packages(Path(self.project_dir), tmp_dir_path)
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/project.py", line 91, in copy_dbt_packages
shutil.copy2(src_path, dst_path)
File "/usr/local/lib/python3.11/shutil.py", line 448, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/local/lib/python3.11/shutil.py", line 256, in copyfile
with open(src, 'rb') as fsrc:
^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/airflow/dags/dbt/pr_3531_13_dbt_vip_enrichment/dbt_packages{{ "_" + env_var("dbt_packages_suffix","") if env_var("dbt_packages_suffix","")!="" }}'
```
This is because when we implemented
#1768 we did not
forsee the parameter could be a template.
This PR aims to solve this issue.
Observation: we'll need to release this not only as part of 1.12.0, but
also cherry-pick it and, exceptionally, backport it to v1.10.3 and
1.11.3.
(cherry picked from commit 4a906cd)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The feature introduced in #1670 (Support running
dbt depsincrementally to pre-defineddbt_packagesduring task execution) did not work as expected if users had defined a custom path forpackages-install-path. It only worked if the default (dbt_packageswas being used. This PR aims to solve the issue.